タグ

2012年11月3日のブックマーク (10件)

  • N3059

    👻 道化師 🃏 @wraith13 次の(  )に当てはまる適切な言葉を述べよ。(10点):「(std::)tie が(  )していてよ。」 [電波注意] 2010-04-28 00:43:41

    N3059
  • In-Place Factories - 1.49.0

    rydot
    rydot 2012/11/03
  • letsboost::in_place_factory

    sample サンプルの動作確認バージョン [GCC4.4/1.41.0] [VC9/1.41.0] // boost::optional的な物の再開発 #include <new> #include <boost/utility/in_place_factory.hpp> template<typename T> class my_optional { public: my_optional() : storage(0) {} template<class InPlace> my_optional( const InPlace& p ) : storage(reinterpret_cast<T*>(new char[sizeof(T)])) { p.template apply<T>(storage); } ~my_optional() { delete storage; } opera

  • Boost.Optional と Boost.InPlaceFactory で初期化遅延 - 野良C++erの雑記帳

    boost::optional は「値 T あるいは無効値」を取ることのできるクラスです。 通常このクラスは、「失敗するかもしれない」関数の戻り値として使用されます: #include <boost/optional.hpp> #include <iostream> // 例として std::getline を optional で実装してみる boost::optional<std::string> getline_optional( std::istream& in ) { std::string result; if( getline( in, result ) ) { // 行の読み取りに成功 return result; } // 失敗。無効値( boost::none )を返す return boost::none; } int main() { // cat コマンドっぽい挙

    Boost.Optional と Boost.InPlaceFactory で初期化遅延 - 野良C++erの雑記帳
  • サービス終了のお知らせ - NAVER まとめ

    サービス終了のお知らせ NAVERまとめは2020年9月30日をもちましてサービス終了いたしました。 約11年間、NAVERまとめをご利用・ご愛顧いただき誠にありがとうございました。

    サービス終了のお知らせ - NAVER まとめ
    rydot
    rydot 2012/11/03
  • C でクロージャ。 : torus solutions!

    クロージャが使えると、 それを使っていろんなことが可能になるので、 C でも似たことができないか試してみた。 内部状態をもつ簡単なカウンタを作ってみます。 最初に初期値を指定して、 呼び出す時に引数で数値を渡すと、 内部のカウンタがそれだけ増えて、 カウンタの値を返すというクロージャです。 Scheme だと Scheme で普通に書くと、 こんな風になると思います。 (define (make_counter k) (let ((n k)) (lambda (a) (set! n (+ n a)) n))) こうやってクロージャを返す関数を作って、 (define c1 (make_counter 0)) (define c2 (make_counter 5)) 初期値を変えてクロージャを 2 つ生成します。 (print (c1 3)) ; => 3 (print (c2 1)) ;

  • C言語でクロージャ - hogelogの日記

    わりとありがちなネタで。まったく関係ない講義受けてるときにふと思いついた。 #include <stdio.h> #include <string.h> char COUNTER_CODE[] = { 0x55,0x89,0xe5,0xff, 0x05,0x00,0x00,0x00, 0x00,0xa1,0x00,0x00, 0x00,0x00,0xc9,0xc3 }; /* int falsecounter(){ return ++*((int *)0x00); } */ int (*makecounter())(){ char *counter = (char *)malloc(16); unsigned int count = (unsigned int)calloc(1, 4); memcpy(counter, COUNTER_CODE, 16); memcpy(counter+5

    C言語でクロージャ - hogelogの日記
    rydot
    rydot 2012/11/03
  • 404 Blog Not Found:Cで強引にたらいを後回し

    2007年05月22日22:00 カテゴリLightweight Languages Cで強引にたらいを後回し 404 Blog Not Found:λ萌え - たらいを後回しを書いた後、なんとかCでも出来ないかと、車輪の再発明する代わりに横車を押してみた。 GCCにはclosureがある! 実は以外と知られていないが、gccでは無名関数は使えなくとも、closureは使える。最近では無名関数をサポートしている言語が人気ということもあり、また無名関数の多くがclosureとしても用いられているため、無名関数の別名としてclosureという呼び方をすることもあるが(私もときどきやる)。この二つは来は別物である。JavaScriptで書くと、 var outer = 1; var closure = function(x){ return outer++ }; var nonclosure

    404 Blog Not Found:Cで強引にたらいを後回し
  • Why free monads matter

    Interpreters Good programmers decompose data from the interpreter that processes that data. Compilers exemplify this approach, where they will typically represent the source code as an abstract syntax tree, and then pass that tree to one of many possible interpreters. We benefit from decoupling the interpreter and the syntax tree, because then we can interpret the syntax tree in multiple ways. For

  • Free Monad ってなんだろう - xuwei-k's blog

    先日の渋谷での第74回Scala勉強会では、nescalaの資料を読んだのですが 勉強会のwikiページ そのなかで、この資料 Dead-Simple Dependency Injection にでてくる Free Monad について。 勉強会中、とりあえずひと通り読んで、なんとなーく理解した後に 「あれ、これってIOモナドとか他のものでも書けるんじゃね?何が違うんだろう?」 的な意見がでて、だがしかしそれを詳しく説明出来る人もいないし、考えても調べてもすぐに分かるような問題じゃない・・・ので放置してた。 が、まさにそのことについて発表した人が twitter 上で話していたのでメモ。 まぁこれもまた、なんとなくしか理解できてないですが・・・一応怪しい訳で、自分なりに簡単にまとめると Free Monad 以外でも書ける けど、Free Monad で書いたほうがプログラムが明確になる

    Free Monad ってなんだろう - xuwei-k's blog