2008-12-16から1日間の記事一覧

てきとーにスマートポインタを実装する

C++

shared_ptrの仕組みが気になったので、てきとーに実装してみる。 #include <iostream> using namespace std; template <typename T> class Ptr { T *p; int *cnt; public: Ptr(T *p) : p(p) { cnt = new int(1); cout << "count=" << *cnt << endl; } Ptr(const Ptr<T> &self) { p = s</t></typename></iostream>…

boost::asio

C++

boost::asioすごいなー。 #include <iostream> #include <string> #define _WIN32_WINNT 0x0501 #include <boost/asio.hpp> using namespace std; using namespace boost::asio; int main(int argc, char* argv[]) { ip::tcp::iostream s("www.boost.org", "http"); s << "GET / HTTP/1.1\r\n";</boost/asio.hpp></string></iostream>…