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
177 template<
class F,
class G,
class H>
179 public std::binary_function<typename G::argument_type,
180 typename H::argument_type,
181 typename F::result_type>
195 : f_(f), g_(g), h_(h)
202 typename F::result_type
operator()(
typename G::argument_type x,
203 typename H::argument_type y)
const 205 return f_(g_(x), h_(y));
221 template<
class F,
class G,
class H>
249 template<
class F,
class G>
251 public std::binary_function<typename G::first_argument_type,
252 typename G::second_argument_type,
253 typename F::result_type>
274 typename F::result_type
276 typename G::second_argument_type y)
const 295 template<
class F,
class G>
325 template<
class F,
class G>
326 class compose_f_gx :
public std::unary_function<typename G::argument_type,
327 typename F::result_type>
348 typename F::result_type
368 template<
class F,
class G>
401 template<
class F,
class G,
class H>
403 typename F::result_type>
417 : f_(f), g_(g), h_(h)
424 typename F::result_type
operator()(
typename G::argument_type x)
const 426 return f_(g_(x), h_(x));
444 template<
class F,
class G,
class H>
459 struct Exp : std::unary_function<T, T>
465 {
return std::exp(x); }
495 std::vector<T> other;
516 template <
typename Key,
typename Tp,
typename Compare,
typename Alloc,
518 const Tp&
get(
const std::map<Key, Tp, Compare, Alloc>& m,
const Key2& k);
526 template<
typename Key>
536 const Key&
key(
void)
const {
return key_; }
553 template<
typename InputIterator,
typename Key,
typename Comp>
554 void inverse(InputIterator first, InputIterator last,
555 std::map<Key, std::vector<size_t>, Comp >& m)
557 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
558 BOOST_CONCEPT_ASSERT((boost::Convertible<
typename std::iterator_traits<InputIterator>::value_type, Key>));
560 for (
size_t i=0; first!=last; ++i, ++first)
561 m[*first].push_back(i);
572 template<
typename Key,
typename InputIterator,
typename Comp>
573 void inverse(InputIterator first, InputIterator last,
574 std::multimap<Key, size_t, Comp>& m)
576 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
577 BOOST_CONCEPT_ASSERT((boost::Convertible<
typename std::iterator_traits<InputIterator>::value_type, Key>));
579 for (
size_t i=0; first!=last; ++i, ++first)
580 m.insert(std::make_pair(*first, i));
595 template<
typename InputIterator,
typename Key,
typename Comp>
596 void inverse(InputIterator first, InputIterator last,
597 std::map<Key, size_t, Comp >& m)
599 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
600 BOOST_CONCEPT_ASSERT((boost::Convertible<
typename std::iterator_traits<InputIterator>::value_type, Key>));
602 for (
size_t i=0; first!=last; ++i, ++first)
650 : std::binary_function<DataWeight, DataWeight, bool>
671 class Log : std::unary_function<T, T>
683 explicit Log(
double base) : log_base_(
std::log(base)) {}
689 {
return std::log(x)/log_base_; }
698 template <
typename T>
699 T
max(
const T& a,
const T& b,
const T& c)
708 template <
typename T>
709 T
max(
const T& a,
const T& b,
const T& c,
const T& d)
718 template <
typename T>
719 T
max(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e)
728 template <
typename T>
729 T
max(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e,
const T& f)
742 template <
class T1,
class T2>
750 const std::pair<T1,T2>& y) {
751 return ((x.second<y.second) ||
752 (!(y.second<x.second) && (x.first<y.first)));
763 template <
class Pair>
771 typedef typename boost::mpl::if_<
772 typename boost::is_const<Pair>::type,
773 typename boost::add_const<typename Pair::first_type>::type&,
797 template <
class Pair>
805 typedef typename boost::mpl::if_<
806 typename boost::is_const<Pair>::type,
807 typename boost::add_const<typename Pair::second_type>::type&,
842 boost::transform_iterator<
843 PairFirst<
typename boost::remove_reference<
844 typename std::iterator_traits<Iter>::reference
850 typedef typename std::iterator_traits<Iter>::reference ref_type;
851 typedef typename boost::remove_reference<ref_type>::type val_type;
853 return boost::transform_iterator<PF, Iter>(i, PF());
873 boost::transform_iterator<
874 PairSecond<
typename boost::remove_reference<
875 typename std::iterator_traits<Iter>::reference
881 typedef typename std::iterator_traits<Iter>::reference ref_type;
882 typedef typename boost::remove_reference<ref_type>::type val_type;
884 return boost::transform_iterator<PS, Iter>(i, PS());
916 template<
typename Po
inter,
class Compare>
917 compose_f_gx_hy<Compare, Dereferencer<Pointer>, Dereferencer<Pointer> >
930 template<
typename Po
inter>
931 compose_f_gx_hy<std::less<typename std::iterator_traits<Pointer>::value_type>,
932 Dereferencer<Pointer>, Dereferencer<Pointer> >
935 typedef typename std::iterator_traits<Pointer>::value_type value_type;
936 BOOST_CONCEPT_ASSERT((boost::LessThanComparable<value_type>));
937 std::less<value_type> compare;
945 std::string&
to_lower(std::string& s);
950 std::string&
to_upper(std::string& s);
955 template <
typename Key,
typename Tp,
typename Compare,
typename Alloc,
957 const Tp&
get(
const std::map<Key, Tp, Compare, Alloc>& m,
const Key2& key)
959 BOOST_CONCEPT_ASSERT((boost::Convertible<Key2, Key>));
960 typename std::map<Key, Tp, Compare,Alloc>::const_iterator iter(m.find(key));
966 get_error<Key>(
"utility::get(const Map&, const Key&): key not found",
T operator()(T x) const
Definition: stl_utility.h:688
Functor that behaves like std::less with the exception that it treats NaN as a number larger than inf...
Definition: stl_utility.h:627
Functor that return std::pair.second.
Definition: stl_utility.h:798
void inverse(InputIterator first, InputIterator last, std::map< Key, std::vector< size_t >, Comp > &m)
Definition: stl_utility.h:554
Concept check for Trivial Iterator.
Definition: concept_check.h:191
compose_f_gx_hx< F, G, H > make_compose_f_gx_hx(F f, G g, H h)
Definition: stl_utility.h:445
bool operator()(const std::pair< T1, T2 > &x, const std::pair< T1, T2 > &y)
Definition: stl_utility.h:749
T operator()(T x) const
Definition: stl_utility.h:91
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:877
compose_f_gxy(F f, G g)
Constructor.
Definition: stl_utility.h:266
The Department of Theoretical Physics namespace as we define it.
Definition: stl_utility.h:326
T max(const T &a, const T &b, const T &c, const T &d, const T &e, const T &f)
Definition: stl_utility.h:729
Definition: stl_utility.h:402
F::result_type operator()(typename G::argument_type x) const
Does the work.
Definition: stl_utility.h:349
Pair & argument_type
Definition: stl_utility.h:813
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:808
Definition: stl_utility.h:64
void clear(std::vector< T > &vec)
reduce size and capacity to zero
Definition: stl_utility.h:493
virtual ~get_error(void)
destructor
Definition: stl_utility.h:534
F::result_type operator()(typename G::argument_type x) const
Does the work.
Definition: stl_utility.h:424
compose_f_gx_hx(F f, G g, H h)
Constructor.
Definition: stl_utility.h:416
Functor that return std::pair.first.
Definition: stl_utility.h:764
T operator()(T arg) const
Definition: stl_utility.h:477
compose_f_gx_hy(F f, G g, H h)
Constructor.
Definition: stl_utility.h:194
get_error(const std::string &msg, const Key &key)
constructor
Definition: stl_utility.h:531
compose_f_gx_hx(void)
default constructor
Definition: stl_utility.h:411
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:340
T max(const T &a, const T &b, const T &c)
Definition: stl_utility.h:699
Definition: stl_utility.h:250
Class used for all runtime error detected within yat library.
Definition: Exception.h:53
const Key & key(void) const
access the key object
Definition: stl_utility.h:536
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:774
compose_f_gx_hy< F, G, H > make_compose_f_gx_hy(F f, G g, H h)
Definition: stl_utility.h:222
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:846
Adaptor between pointer and pointee interface.
Definition: stl_utility.h:122
compose_f_gxy< F, G > make_compose_f_gxy(F f, G g)
Definition: stl_utility.h:296
Definition: stl_utility.h:671
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:335
Identity functor that returns its argument.
Definition: stl_utility.h:474
compose_f_gxy(void)
default constructor
Definition: stl_utility.h:261
T operator()(T x) const
Definition: stl_utility.h:464
Functor comparing pairs using second.
Definition: stl_utility.h:743
F::result_type operator()(typename G::argument_type x, typename H::argument_type y) const
Does the work.
Definition: stl_utility.h:202
result_type operator()(argument_type p) const
Definition: stl_utility.h:784
compose_f_gx< F, G > make_compose_f_gx(F f, G g)
Definition: stl_utility.h:369
Definition: stl_utility.h:459
compose_f_gx_hy(void)
default constructor
Definition: stl_utility.h:189
bool operator()(const DataWeight &x, const DataWeight &y) const
Definition: stl_utility.h:655
error class used in get(const std::map<Key, Tp, Compare, Alloc>& m, const Key& k) ...
Definition: stl_utility.h:527
std::iterator_traits< Pointer >::reference operator()(Pointer ti) const
Definition: stl_utility.h:136
bool operator()(T x, T y) const
Definition: stl_utility.h:634
Log(double base)
Definition: stl_utility.h:683
F::result_type operator()(typename G::first_argument_type x, typename G::second_argument_type y) const
Does the work.
Definition: stl_utility.h:275
Definition: stl_utility.h:178
Log(void)
Definition: stl_utility.h:677
Pair & argument_type
Definition: stl_utility.h:779
result_type operator()(argument_type p) const
Definition: stl_utility.h:818
compose_f_gx_hy< Compare, Dereferencer< Pointer >, Dereferencer< Pointer > > make_ptr_compare(Pointer p, Compare compare)
Definition: stl_utility.h:918