关于学习boost时的那些零碎记录(回忆里待续)

boost编译这块不多说了,百度文库上有教程.版本之间变化挺大的,比如说timer库的实现,连接口都变了.

教材用的是<boost程序库完全开发指南>,国人写的,因为资料实在比较少,将就着看看.另外,boost自带的英文手册也比较给力.

timer库

计算程序运行时间(基本没用):

progress_timer t;

date_timer是和date计算相关的库,与java很相似,提供了很多便利的函数.


shared_ptr是引用计数型的智能指针,能自由的拷贝和赋值,可以放到标准容器里.可被多个线程安全读取,其他情况未知..

#include <boost/make_shared.hpp>

shared_ptr<string> spstr = new string();

shared_ptr<string> spstr = make_shared<string>("make_shared");
shared_ptr< vector<int> > spvec = make_shared< vector<int> >(3, 2);

int* p = new int[100];
shared_array<int> sa(p);
shared_array<int> sa2 = sa;
sa[0] = 10;


tribool库,好猎奇的一个库啊,除了true和false状态,增加了第三个状态未知状态,平时都是默认设为false状态的,突然整个世界观就被它颠覆了...

#include <boost/logic/tribool.hpp>

tribool tb(indeterminate);

optional库像它的名字一样,无用的...


字符串操作

验证字符串合法性, 与数字之间的相互转化

#include <boost/lexical_cast.hpp>
using namespace boost;

template<typename T>
bool num_valid(const char* str)
{
try
{
lexical_cast<T>(str);
return true;
}
catch(bad_lexical_cast&)
{
return false;
}
}

int _tmain(int argc, _TCHAR* argv[])
{
try
{
int x = lexical_cast<int>("100");
float pai = lexical_cast<float>("3.14159");
string str = lexical_cast<string>(123);
cout << "x: " << x << " pai: " << pai << " str: " << str << endl;
}
catch(bad_lexical_cast& e)
{
cout << "error: " << e.what() << endl;
}


assert(num_valid<double>("3.14"));

return 0;
}

#include <boost/algorithm/string.hpp>

string_algo应该有的差不多都有了,比java还完善..

函数命名中:

前缀i:有表示大小写敏感的

后缀_copy:有表示不变动输入,返回处理结果的拷贝,否则输入即输出

后缀_if:表面这个算法需要一个作为判断式的谓词函数对象,否则使用默认的判断准则.

to_upper();to_lower();starts_with(); ends_with(); contains(); equals(); all(); is_less(); is_not_greater();

检测字符特性也有一套函数:

修剪算法可以删除字符串开头或结尾部分的空格

查找,替换,删除,分割,合并...


分词库(tokenizer),瞟了一眼,蛋都碎了..

xpressive 正则表达式库,boost.regex的替代品



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值