boost learn notes

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 (转载请注明出处)

posted on 2013-05-07 10:13  Jalen Wang  阅读(186)  评论(0编辑  收藏  举报

导航