boost函数:clamp、gather、hex、is_palindrome
来源:互联网 发布:mac版itunes导入铃声 编辑:程序博客网 时间:2024/05/02 09:08
clamp:
template<typename T, typename Pred> T const & clamp ( T const& val, typename boost::mpl::identity<T>::type const & lo, typename boost::mpl::identity<T>::type const & hi, Pred p ) {// assert ( !p ( hi, lo )); // Can't assert p ( lo, hi ) b/c they might be equal return p ( val, lo ) ? lo : p ( hi, val ) ? hi : val; }
简述:给定三个数,返回中间数(Pred默认使用std::less)。
示例:
int foo = 23; foo = boost::algorithm::clamp(foo, 1, 10); cout << foo << endl;
gather:
template < typename BidirectionalIterator, // Iter models BidirectionalIterator typename Pred> // Pred models UnaryPredicatestd::pair<BidirectionalIterator, BidirectionalIterator> gather ( BidirectionalIterator first, BidirectionalIterator last, BidirectionalIterator pivot, Pred pred ){// The first call partitions everything up to (but not including) the pivot element,// while the second call partitions the rest of the sequence. return std::make_pair ( std::stable_partition ( first, pivot, !boost::bind<bool> ( pred, _1 )), std::stable_partition ( pivot, last, boost::bind<bool> ( pred, _1 )));}
简述:将容器中满足pred函数要求的元素聚集到pivot的两边,并返回满足元素的区间迭代器。
stable_partition函数作用是依据pred函数将容器分为两部分(前一部分满足函数要求,后一部分不满足函数要求),且元素的相对位置不发生变化。
示例:
int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; auto range = boost::algorithm::gather(arr, arr + 10, arr + 4, isEven); //13 0 2 4 6 8 5 7 9 for(auto i = 0; i < sizeof(arr) / sizeof(int); ++i) { cout << *(arr + i) << " "; } cout << endl; //02 4 6 8 for(auto ite = range.first; ite != range.second; ++ite) { cout << *ite << " "; } cout << endl;
hex:
is_palindrome:
0 0
- boost函数:clamp、gather、hex、is_palindrome
- Clamp函数
- Boost 学习之算法篇 clamp
- Boost 学习之算法篇 gather
- c# hex函数
- Boost 学习之算法篇 hex
- clamp用法
- Mathf.Clamp
- 【练习题】编写一个名为is_palindrome的函数,判断一个人名是否为回文,如‘BOB’是回文
- MYSQL中HEX、UNHEX函数
- Hex
- HEX
- hex
- Hex
- Hex
- HEX
- mysql的hex()和unhex()函数
- mysql hex与unhex 函数的妙用
- git操作错误Failed to resolve HEAD as a valid ref解决方案
- Retrofit的使用
- 利用localStorage防止页面动态添加数据刷新后数据丢失
- JDBC连接MySQL基本步骤代码块
- 行为型模式之策略STRATEGY
- boost函数:clamp、gather、hex、is_palindrome
- 关于操作系统的几个重要概念(二)
- java优化
- CXF初体验(一)
- 行为识别笔记:C3D network-用于视频特征提取的3维卷积网络
- Elasticsearch 批量导入数据
- 形象的讲解angular中的$q与promise
- BZOJ1108 [POI2007]天然气管道Gaz
- web优化