http://blog.sina.com.cn/shakalcf[订阅]
个人资料
分类
    内容读取中…
评论
读取中...
访客
读取中...
好友
读取中...
音乐播放器
博文
PythonWin的一个问题(2008-11-29 18:18)

当字符串包含'\0'之类的字符串, ActiveState ActivePython 2.5会对其后面的内容截断,扰乱调试。

boost -- tuple(2008-11-11 20:29)

#include <string>
#include <boost/tuple/tuple.hpp>
using namespace boost::tuples;

void test()
{
 tuple<int, std::string> bunch = make_tuple(2, std::string('word'));
 int v1 = bunch.get<0>();
 std::string v2 = bunch.get<1>();
 v1 = sizeof(bunch);
}

boost -- pool(2008-11-11 20:28)

#include <boost/pool/pool.hpp>
#include <boost/pool/pool_alloc.hpp>
#include <boost/pool/object_pool.hpp>
#include <boost/timer.hpp>

#include <iostream>
#include <vector>
#include <cassert>

 

struct chunk
{
 char _data[8];
};

void test_pool()
{
 boost::pool<> _pool(sizeof(chunk));
 chunk* ptr1 = static_cast<chunk*>(_pool.malloc());
 chunk* ptr2 = static_cast<chunk*>(_pool.malloc());
 _pool.free(ptr1);
 _pool.free(ptr2);
}

void test_std_alloc_vector(int const& loop)
{
 std::vector<chunk*> _vector;

boost -- lambda(2008-11-11 20:25)

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/assign/std.hpp>
#include <boost/function.hpp>
#include <boost/ref.hpp>
using namespace boost::lambda;

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cassert>

 

int block(int const& left, int const& right)
{
 return (left + right);
}

struct blocker
{
 typedef int result_type;

 blocker(int const& left, int const& right)
 : left_(left), right_(right) {}

 

boost -- format(2008-11-11 20:24)

#include <assert.h>
#include <boost/format.hpp>

void test()
{
 boost::format fm('%1%/%2%.%3%');
 fm % 10 % 'hello' % 30;
 assert('10/hello.30' == fm.str());
 fm.clear_binds();
 fm % 10 % 'world' % 30;
 assert('10/world.30' == fm.str());
}

boost -- embedding python(2008-11-11 20:23)

#include <cstdlib>
#include <boost/python.hpp>

 

int main(int argc, char* argv[])
{
 Py_Initialize();
 {
  long value = 100; // C++ long
  boost::python::object _module = boost::python::import('math');
  boost::python::object _log10 = _module.attr('log10');
  boost::python::object _result = _log10(value);
  float result = boost::python::extract<float>(_result);
 }
 {
  boost::python::object _module = boost::python::import('math');
  boost::python::object _log10 = _module.attr('log10');
  boost::python::long_  _value(100); // Python long
  boost::python::object _result = _log10(_value);
  float result = boost::python::extract<

boost -- dutch(2008-11-11 20:22)

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <iostream>
#include <algorithm>
using boost::asio::ip::tcp;

 

class session
 : public boost::enable_shared_from_this<session>
{
public:
 typedef boost::shared_ptr<session> shared_ptr;

 session(boost::asio::io_service& io_service)
  : socket_(io_service)
 {
  zero_data();
 }

 void start()
 {

  std::cout << 'accepted '
      <&

boost -- conversion(2008-11-11 20:20)

#include <boost/lexical_cast.hpp>
using boost::lexical_cast;
using boost::bad_lexical_cast;

#include <string>
using std::string;

#include <assert.h>

 

void str_to_int()
{
 try
 {
  int value = lexical_cast<int>('100');
 }
 catch (bad_lexical_cast&)
 {
  assert(false);
 }
}

void test_conversion()
{
 str_to_int();
}

boost -- bimap(2008-11-11 20:19)

#include <assert.h>

#include <boost/bimap.hpp>
#include <boost/bimap/support/lambda.hpp>
#include <string>
using namespace std;

 

void test_left_map_view()
{
 
 typedef boost::bimap<int, string> map_type;
 typedef boost::bimap<int, string>::value_type value_type;
 map_type key_value;
 key_value.insert(value_type(1, 'one'));
 key_value.insert(value_type(2, 'two'));

 {
  map_type::left_iterator iter = key_value.left.find(1);
  bool replaced = key_value.left.replace_data(iter, 'two');
  assert(!replaced);
  assert(2 == key_value.size());
 }

 

boost -- array(2008-11-11 20:17)

#include <boost/array.hpp>

 

class temp
{
public:
 int v1;
 int v2;
};

void test()
{
 temp t = {1, 2};
 boost::array<char, 10> buff = {'1', '2'};
}