melt日記

.NETすらまともに扱えないへたれのページ

ホーム 連絡をする 同期する ( RSS 2.0 ) Login
投稿数  111  : 記事  3  : コメント  8241  : トラックバック  41

ニュース

わんくま同盟

わんくま同盟

C# と VB.NET の質問掲示板

iKnow!


Dictation



書庫

Boost に正式に入るのかどうか知りませんが、Boost.Coroutine というのがあります。


C# で言う yield のようなものですが、ステートマシンに置き換えているわけではなく、内部でコンテキストを切り替えているだけのようです。


で、Boost.Coroutine のサンプルを見てみましたが、超面白そうです。

class range_generator {
public:
  typedef int value_type;

  range_generator(int min, int max) :
    m_current(min),
    m_max(max) {}

  range_generator() :
    m_current(-1),
    m_max(0) {}

  int operator*() {
    return m_current;
  }
  
  range_generator& operator++() {	
    m_current ++;
    if(m_current == m_max)
      m_current = -1;
    return *this;
  }    

  range_generator operator++(int) {
    range_generator t(*this);
    ++*this;
    return t;
  }

  friend
  bool operator==(const range_generator& rhs,
    const range_generator& lhs) {
    return rhs.m_current == lhs.m_current;
  }

  friend
  bool operator!=(const range_generator& rhs,
    const range_generator& lhs) {
    return !(rhs == lhs);
  }

  private:
  int m_current;
  int m_max;
};
range_generator generator(100, 200);

while(generator != range_generator()) 
  std::cout<<*generator++<<"\n";

こんな長いコードが、

int range_generator(generator_type::self& self, 
      int min,
      int max) 
{
  while(min < max-1)
    self.yield(min++);
  return min;  
}
generator_type generator
  (boost::bind
   (range_generator, 
    _1, 
    100,
    200));

while(generator != generator_type()) 
  std::cout<<*generator++<<"\n";

こんな風になります。

イテレータに状態を持つ必要のないことの楽さといったらもう。


この変態ライブラリは機会があれば是非とも使ってみようと思います。

投稿日時 : 2008年3月28日 10:09

コメント

# re: [C++]Boost.Coroutine 2008/03/28 10:52 アキラ
ころーたいん?

なるほど。異なるイテレーションのためにイテレータを作らなくていいということですね(で合ってるのかな)

数値の範囲だけならこういう風にできるようにしますけどね
(ちょっと前にmb2syncさんのを参考にして作ったw)
foreach (int i, count_range(100, 200)) {
}

foreach (int i, zero_to(10)) {
}

# re: [C++]Boost.Coroutine 2008/03/28 12:46 melt
>ころーたいん?
コルーチンでっす。
micro thread とか fiber とか呼ばれてるやつです。

関数の途中で凍結させて、もう一度呼び出すとその途中から始められるというやつです。
こうすると、受動的なメソッドを能動的に書くことが出来るようになるので、状態管理が楽になったりすることがあります。

# re: [C++]Boost.Coroutine 2008/03/29 9:40 MB
ころーたいん かわいい 笑
http://p-stade.sourceforge.net/oven/doc/html/oven/ranges.html#oven.ranges.block
こんなのも作りました
もともと作ったのはhamigakiさんですけど

# re: [C++]Boost.Coroutine 2008/03/31 11:47 アキラ
> ころーたいん
マジメに読めませんでした;;

# Тут есть много нужного и интересного 2011/12/25 7:34 PootoLypeflet
главное что бесплатно http://st-tds.com/?pid=5&wkey=40372

# Тут есть много нужного и интересного 2011/12/25 20:43 PootoLypeflet
главное что бесплатно http://st-tds.com/?pid=5&wkey=40372

# best shop 2012/01/18 13:08 dahinnolanask
hifrino.ru for slimming
http://hifrino.ru/ for slimming

# how to write an admissions essay for graduate school w324md 2022/09/08 19:11 AaronBlact

With thanks. Excellent stuff! https://definitionessays.com/ seo article writing service

# steps to writing an argumentative essay v396qj 2023/02/10 6:23 Albertosed

Nicely put, Regards.
https://essaywritingservicelinked.com/ coursework history

# buy an essay uk k183fv 2023/02/26 8:16 CharlesSnoff

Useful stuff. Regards!
buy narrative essay https://quality-essays.com/ pay someone to write your essay

# a thesis l577vx 2023/03/02 21:40 Josephbried

Nicely voiced of course! .
writing a thesis sentence https://writingthesistops.com/ service learning thesis statement

# writing a dissertation methodology k93soo 2023/03/06 16:36 EugeneSib
You actually expressed this really well.
the best college essay https://buyanessayscheaponline.com wikipedia essay writer https://customthesiswritingservice.com

# personal essay for college admission r677ss 2023/03/06 21:18 Gregorysaipt

Lovely data, Appreciate it!
write an essay https://writingresearchtermpaperservice.com how to write an about me essay https://phdthesisdissertation.com

# website essay i98eko 2023/03/07 23:06 EugeneSib

Useful posts. Cheers.
college application essay service https://essaywritingservicehelp.com write my college essay https://writingpaperforme.com

# college essay requirements r61oqg 2023/03/08 14:34 EugeneSib

Regards, Loads of posts.
college essays help https://studentessaywriting.com college essay sports https://argumentativethesis.com

# 250 word college essay d973og 2023/03/09 7:27 EugeneSib

Wonderful information. Appreciate it!
proposal dissertation https://essaywritingservicehelp.com essay why i want to go to college https://buycheapessaysonline.com

# how to do essay writing i75out 2023/03/09 22:06 EugeneSib

Many thanks! I like it.
essay writing website https://hireawriterforanessay.com writing a rhetorical analysis essay https://essaywritingserviceahrefs.com

# how to write a introduction for an essay e70owv 2023/03/10 13:16 Gregorysaipt
You actually suggested it wonderfully!
argument essay writing https://domyhomeworkformecheap.com how to write a play name in an essay https://writinganessaycollegeservice.com

# college entrance essay y60qdf 2023/03/12 9:07 EugeneSib

Kudos. Useful information!
best writing essay https://researchpaperwriterservices.com writing good essays https://buycheapessaysonline.com

# dissertation services r328ua 2023/03/12 23:39 EugeneSib
You stated that perfectly!
dissertation doctor https://quality-essays.com how to write a narrative essay introduction https://bestmasterthesiswritingservice.com

# autobiography college essay v61ewy 2023/03/13 6:30 Gregorysaipt
You actually mentioned this wonderfully!
how to write a short essay https://dissertationwritingtops.com how to write the introduction of an essay https://argumentativethesis.com

# writing an abstract for dissertation b970ds 2023/03/13 14:17 EugeneSib
You reported that really well!
doctorate dissertation https://essaywritingservicelinked.com how to write an essay for an application https://essaywritingservicelinked.com

# essay writing rubrics m22fif 2023/04/02 22:00 EugeneSib

Thanks, I value it!
essay writing music https://customthesiswritingservice.com argumentative essay writing prompts https://writingresearchtermpaperservice.com

# The plugins developed for WordPress 2023/05/10 0:45 Justas
The plugins developed for WordPress serve to enhance the features and functions of a WordPress website, allowing you to build your awesome and functional site https://t.me/wpigaming/648 Customise WordPress with powerful, professional and intuitive fields.

# versandapotheke 2023/09/26 13:11 Williamreomo
http://onlineapotheke.tech/# online apotheke versandkostenfrei
versandapotheke

# online apotheke preisvergleich 2023/09/27 2:00 Williamreomo
http://onlineapotheke.tech/# versandapotheke
online apotheke preisvergleich

# internet apotheke 2023/09/27 3:24 Williamreomo
http://onlineapotheke.tech/# versandapotheke
п»?online apotheke

# online apotheke deutschland 2023/09/27 4:19 Williamreomo
http://onlineapotheke.tech/# online apotheke deutschland
versandapotheke deutschland

# online apotheke gГјnstig 2023/09/27 5:34 Williamreomo
http://onlineapotheke.tech/# versandapotheke versandkostenfrei
versandapotheke

# п»їonline apotheke 2023/09/27 8:07 Williamreomo
https://onlineapotheke.tech/# versandapotheke deutschland
online apotheke gГ?nstig

# п»їonline apotheke 2023/09/27 11:18 Williamreomo
http://onlineapotheke.tech/# gГ?nstige online apotheke
versandapotheke

# gГјnstige online apotheke 2023/09/27 13:08 Williamreomo
https://onlineapotheke.tech/# versandapotheke deutschland
internet apotheke

# farmacie online autorizzate elenco 2023/09/27 18:09 Rickeyrof
acheter sildenafil 100mg sans ordonnance

# acquisto farmaci con ricetta 2023/09/27 18:25 Rickeyrof
acheter sildenafil 100mg sans ordonnance

# farmacia online 2023/09/27 18:41 Rickeyrof
acheter sildenafil 100mg sans ordonnance

# mail order canada 2023/10/14 22:45 Kiethamert
http://gabapentin.world/# gabapentin generic

# canadian pharmcy 2023/10/17 8:15 Dannyhealm
I'm impressed with their commitment to customer care. https://mexicanpharmonline.com/# mexican mail order pharmacies

# order meds from canada 2023/10/17 19:00 Dannyhealm
A beacon of reliability and trust. https://mexicanpharmonline.com/# mexico drug stores pharmacies

# online canadian pharmacies 2023/10/17 20:42 Dannyhealm
Always up-to-date with international medical advancements. http://mexicanpharmonline.shop/# pharmacies in mexico that ship to usa

# best online indian pharmacies 2023/10/18 12:14 Dannyhealm
Speedy service with a smile! http://mexicanpharmonline.com/# pharmacies in mexico that ship to usa

# best online canadian pharmacies 2023/10/19 0:59 Dannyhealm
Always stocked with the best brands. https://mexicanpharmonline.com/# mexico drug stores pharmacies

# mexican rx online 2023/11/15 15:56 DavidFap
http://mexicopharm.shop/# mexican pharmaceuticals online

# buy paxlovid online 2023/12/01 7:33 Mathewhip
paxlovid cost without insurance http://paxlovid.club/# paxlovid

# my canadian drug store 2023/12/02 11:56 MichaelBum
https://paxlovid.club/# paxlovid buy

# rx prices 2023/12/03 2:09 MichaelBum
http://paxlovid.club/# buy paxlovid online

# farmacia online madrid 2023/12/07 14:35 RonnieCag
http://farmacia.best/# farmacia online madrid

# farmacia barata 2023/12/07 17:35 RonnieCag
https://tadalafilo.pro/# farmacias online baratas

# farmacia online barata 2023/12/07 20:50 RonnieCag
https://tadalafilo.pro/# farmacia online envío gratis

# farmacias baratas online envío gratis 2023/12/08 3:09 RonnieCag
http://tadalafilo.pro/# farmacia online barata

# farmacias online seguras en españa 2023/12/08 9:01 RonnieCag
http://tadalafilo.pro/# farmacias online seguras en españa

# farmacias baratas online envío gratis 2023/12/08 11:49 RonnieCag
https://sildenafilo.store/# sildenafilo 100mg sin receta

# farmacia online 24 horas 2023/12/09 12:18 RonnieCag
https://tadalafilo.pro/# farmacia online 24 horas

# farmacia 24h 2023/12/09 15:11 RonnieCag
http://farmacia.best/# farmacia barata

# farmacias online seguras en españa 2023/12/10 1:06 RonnieCag
http://sildenafilo.store/# sildenafilo 50 mg comprar online

# farmacias online seguras en españa 2023/12/10 4:55 RonnieCag
https://farmacia.best/# farmacia online madrid

# farmacias baratas online envío gratis 2023/12/10 8:26 RonnieCag
https://vardenafilo.icu/# farmacia barata

# farmacias baratas online envío gratis 2023/12/10 17:30 RonnieCag
https://tadalafilo.pro/# farmacias baratas online envío gratis

# farmacias baratas online envío gratis 2023/12/12 15:23 RonnieCag
https://vardenafilo.icu/# farmacias baratas online envío gratis

# Pharmacie en ligne fiable 2023/12/14 1:30 Larryedump
http://pharmacieenligne.guru/# Pharmacie en ligne fiable

# Pharmacies en ligne certifiées 2023/12/14 9:01 Larryedump
http://pharmacieenligne.guru/# Pharmacies en ligne certifiées

# ï»¿pharmacie en ligne 2023/12/14 11:53 Larryedump
https://pharmacieenligne.guru/# Pharmacies en ligne certifiées

# pharmacie ouverte 2023/12/14 15:12 Larryedump
http://pharmacieenligne.guru/# Pharmacie en ligne livraison 24h

# Pharmacie en ligne livraison rapide 2023/12/14 23:21 Larryedump
http://pharmacieenligne.guru/# Pharmacie en ligne France

# ï»¿pharmacie en ligne 2023/12/15 22:14 Larryedump
http://pharmacieenligne.guru/# Acheter médicaments sans ordonnance sur internet

# paxlovid for sale 2023/12/28 6:25 Brianmooda
https://clomid.site/# can you buy generic clomid pills

# best ed pills at gnc 2024/01/08 22:55 CharlesDioky
http://edpillsdelivery.pro/# best over the counter ed pills

# best ed treatment pills 2024/01/10 5:08 CharlesDioky
https://tadalafildelivery.pro/# tadalafil generic in usa

# buy cytotec online 2024/01/13 8:26 Keithturse
https://furosemide.pro/# buy lasix online

# farmacia online miglior prezzo 2024/01/15 22:02 Wendellglaks
http://avanafilitalia.online/# farmaci senza ricetta elenco

# farmacia online migliore 2024/01/16 4:38 Robertopramy
http://farmaciaitalia.store/# farmacia online senza ricetta

# top farmacia online 2024/01/16 19:58 Wendellglaks
https://avanafilitalia.online/# farmacia online migliore

# farmacie online sicure 2024/01/17 1:44 Wendellglaks
http://tadalafilitalia.pro/# farmacia online più conveniente

# farmacie on line spedizione gratuita 2024/01/17 7:33 Wendellglaks
http://farmaciaitalia.store/# farmaci senza ricetta elenco

# can i get clomid online 2024/01/21 16:26 LarryVoP
Their health awareness programs are game-changers http://clomidpharm.shop/# where to buy clomid without insurance

# buying generic clomid 2024/01/21 20:30 AnthonyAnoth
https://cytotec.directory/# buy cytotec online fast delivery

# tamoxifen therapy 2024/01/21 21:26 Normantug
http://prednisonepharm.store/# prednisone best prices

# cost of generic clomid 2024/01/22 9:24 LarryVoP
I've never had to wait long for a prescription here http://cytotec.directory/# order cytotec online

# Pharmacie en ligne livraison gratuite 2024/01/27 21:00 JerryNef
https://pharmadoc.pro/# Pharmacie en ligne fiable

# ivermectin pill cost 2024/01/30 12:09 Andrewamabs
http://clomiphene.icu/# where to get clomid prices

# cytotec buy online usa 2024/02/29 17:12 Irvinliz
https://cytotec24.shop/# purchase cytotec

# free singles dating search 2024/03/03 5:42 RodrigoGrany
https://angelawhite.pro/# Angela White video

# local singles near me free 2024/03/03 17:14 RodrigoGrany
http://abelladanger.online/# abella danger video

# free gay dating sites chat 2024/03/04 11:21 RodrigoGrany
http://angelawhite.pro/# ?????? ????

# dating services contact australia 2024/03/05 4:01 RodrigoGrany
https://abelladanger.online/# abella danger izle

# 1 dating sites 2024/03/05 12:23 RodrigoGrany
https://evaelfie.pro/# eva elfie izle

# dating services online 2024/03/06 23:09 HowardBox
ourtime login: https://evaelfie.site/# eva elfie hd

# dating best site 2024/03/09 4:40 HowardBox
single women darling side: https://sweetiefox.pro/# sweetie fox video

# free local dates 2024/03/10 0:16 HowardBox
dating awareness womenв??s network: https://miamalkova.life/# mia malkova only fans

# canadian and international prescription service 2024/03/23 10:36 Carloshab
https://mexicanpharm.online/# mexican mail order pharmacies

# gates of olympus slot 2024/03/30 6:04 KeithNaf
https://aviatoroyna.bid/# aviator sinyal hilesi ucretsiz

# doxycycline 100mg online 2024/04/12 20:30 Archiewef
https://doxycyclinest.pro/# doxycycline

# diflucan cream india 2024/04/14 18:03 Josephfep
http://clomida.pro/# where can i buy clomid for sale

# 3 diflucan pills 2024/04/15 11:40 Josephfep
http://prednisonea.store/# prednisone 20

Post Feedback

タイトル
名前
Url:
コメント