boost learn notes

<?xml version="1.0" encoding="utf-8"?> boost learn notes

boost learn notes

Get Started

example.cpp

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}

Build it

cl /EHsc /I <path-to-boost> example.cpp

Run initcl if cl is not available.

Run it

echo 1 2 3 | example

Further reading material

boost::any

以单个对象接受所有型别的数据,以any_cast取出数据。

template<typename ValueType>
ValueType * any_cast(any * operand)
{
        return operand && operand->type() == typeid(ValueType) ? &static_cast<any::holder<ValueType> *>(operand->content)->held:0;
}

boost::type_traits

type traits的动机是分派,已实现函数重载。

is_array的简化版
template<bool b_>  
struct bool_type{  
    static const bool value = b_;  
};  
  
template<bool b_>  
const bool bool_type<b_>::value;  
  
template<typename T>  
struct is_array : bool_type<false>{  
};  
  
template<typename T>  
struct is_array<T[]>: bool_type<true>{  
};  
  
template<typename T, unsigned int N>  
struct is_array<T[N]> : bool_type<true>{  
};  
  
  
  
int main()  
{  
    bool is_1 = is_array<int[]>::value;  
    bool is_2 = is_array<int[5]>::value;  
    bool is_3 = is_array<int>::value;  
} 

Post by: Jalen Wang (转载请注明出处)

转载于:https://www.cnblogs.com/jalenwang/archive/2013/05/07/3064233.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值