したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | メール | |

管理人の独り言(プログラミング関連)

3375ACUVE★:2011/03/08(火) 01:29:38
某所のscope_guradのコピペ。
-----
#include&nbsp;<utility>

#define&nbsp;PP_CAT(a,&nbsp;b)&nbsp;PP_CAT_I(a,&nbsp;b)
#define&nbsp;PP_CAT_I(a,&nbsp;b)&nbsp;a&nbsp;##&nbsp;b

template<typename&nbsp;F>
struct&nbsp;scope_exit_t&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;scope_exit_t(F&nbsp;&&nbsp;f)&nbsp;:&nbsp;f(f)&nbsp;{}
&nbsp;&nbsp;&nbsp;&nbsp;~scope_exit_t()&nbsp;{&nbsp;f();&nbsp;}
private:
&nbsp;&nbsp;&nbsp;&nbsp;F&nbsp;&&nbsp;f;
};

template<typename&nbsp;F>
struct&nbsp;scope_exit_t<F&&>&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;scope_exit_t(F&nbsp;&&&nbsp;f)&nbsp;:&nbsp;f(f)&nbsp;{}
&nbsp;&nbsp;&nbsp;&nbsp;~scope_exit_t()&nbsp;{&nbsp;f();&nbsp;}
private:
&nbsp;&nbsp;&nbsp;&nbsp;F&nbsp;f;
};

struct&nbsp;scope_exit_helper&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;template<typename&nbsp;F>
&nbsp;&nbsp;&nbsp;&nbsp;scope_exit_t<F&&>&nbsp;operator->*(F&nbsp;&&&nbsp;f)&nbsp;const&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;scope_exit_t<F&&>(std::forward<F>(f));
&nbsp;&nbsp;&nbsp;&nbsp;}
};

#define&nbsp;scope_exit_base&nbsp;auto&nbsp;const&nbsp;PP_CAT(scope_exit_,&nbsp;__LINE__)&nbsp;=&nbsp;scope_exit_helper()&nbsp;->*
#define&nbsp;scope_exit&nbsp;scope_exit_base&nbsp;[&]&nbsp;()
#define&nbsp;scope_exit_2&nbsp;scope_exit_base


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板