<?xml version="1.0" encoding="UTF-8" ?><rdf:RDF 
  xmlns="http://purl.org/rss/1.0/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xml:lang="ja">
  <channel rdf:about="http://w.atwiki.jp/mlnk/">
    <title>備忘録 @ ウィキ</title>
    <link>http://w.atwiki.jp/mlnk/</link>
    <atom:link href="https://w.atwiki.jp/mlnk/rss10.xml" rel="self" type="application/rss+xml" />
    <atom:link rel="hub" href="https://pubsubhubbub.appspot.com" />
    <description>備忘録 @ ウィキ</description>

    <dc:language>ja</dc:language>
    <dc:date>2009-08-11T15:44:45+09:00</dc:date>
    <utime>1249973085</utime>

    <items>
      <rdf:Seq>
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/35.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/38.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/2.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/33.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/34.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/37.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/27.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/36.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/12.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/mlnk/pages/19.html" />
              </rdf:Seq>
    </items>
	
		
    
  </channel>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/35.html">
    <title>C++/tips</title>
    <link>https://w.atwiki.jp/mlnk/pages/35.html</link>
    <description>
      #contents

----
** 暗黙の型変換を引数に使う
暗黙の型変換を引数に使うためには引数は値渡しでないといけない。
#codehighlight(C++){{
struct A{
	A(){}
	A(int){}
};

void f(A, A) {}
void g(A&amp;, A&amp;) {}

int main()
{
	f(1, 2); // OK
	//g(1, 2); // エラー

	return 0;
}
}}

----

** 目的別探索方法

|~何を知りたいか|&gt;|~使用するアルゴリズム|&gt;|~使用するメンバ関数|h
|~|~未ソートの範囲|~ソート済み範囲|~set または map|~multiset または multimap|h
||CENTER:|CENTER:|CENTER:|CENTER:|c
|必要な値が存在するか?|find|binary_search|count|find|
|必要な値が存在するか? 存在するなら、その値を持つ最初のオブジェクトはどこにあるか?|find|equal_range|find|find または lower_bound((findは特定の値を持つ要素のうち「1つ」を見つけるだけ。「最初」の要素が必要ならlower_boundを使う必要がある。))|
|必要な値より前にない値を持つ最初のオブジェクトはどこにあるか?|find_if|lower_bound|lower_bound|lower_bound|
|必要な値の次にある値を持つ最初のオブジェクトはどこにあるか?|find_if|upper_bound|upper_bound|upper_bound|
|必要な値を持つオブジェクトはいくつあるか?|count|equal_range|count|count|
|必要な値を持つすべてのオブジェクトはどこにあるか|find (繰り返し処理)|equal_range|equal_range|equal_range|

----

** lower_bound、uppder_bound、equal_range の返すイテレータの場所
- lower_bound は同値の最初の要素を返す。同値の要素がない場合はそれ未満で最大の要素の次を返す。
- upper_bound は同値の要素の中で一番後ろの要素の次を返す。同値の要素がない場合はそれより大きい最小の要素を返す。
- equal_range はlower_bound と upper_bound の戻り値の組を返す。
-- というか lower_bound も upper_boundも「その値が挿入されるべき位置」という意味では同じか。それが前か後ろかの違いだけで。

*** 要素がある場合
- 1 を探す場合
|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|c
|1|1|3|3|5|5||
|lower_bound||upper_bound|||||

- 3 を探す場合
|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|c
|1|1|3|3|5|5||
|||lower_bound||upper_bound|||

- 5 を探す場合
|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|c
|1|1|3|3|5|5||
|||||lower_bound||upper_bound|

*** 要素がない場合
- 0 を探す場合
|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|c
|1|1|3|3|5|5||
|lower_bound&amp;br;upper_bound|||||||

- 2 を探す場合
|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|c
|1|1|3|3|5|5||
|||lower_bound&amp;br;upper_bound|||||

- 6 を探す場合
|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|CENTER:70|c
|1|1|3|3|5|5||
|||||||lower_bound&amp;br;upper_bound|

----
** イテレータの無効化のタイミング
- vector
-- Reallocationが起きると参照・ポインタ・イテレータ全て無効化される。
-- reserve…reserveする大きさが現在のcapacityより大きければReallocationが起きる
-- insert,push_back…sizeがcapacity超えるとReallocationが起きる
-- erase…eraseした点より後ろの全ての参照・イテレータ無効化
- deque
-- insert…中間点への挿入はイテレータ・参照ともに全て無効化、最後への挿入(==push_back)はイテレータは全て無効化するが参照は有効のままである。
-- erase…中間点の削除はイテレータ・参照ともに全て無効化、最後の削除は削除された要素に対するイテレータ・参照のみ無効化
- list
-- insert,push_front,push_back…イテレータ・参照ともに全て有効のまま
-- erase…削除された要素に対するイテレータ・参照のみ無効化
-- splice
--- splice(pos, x)は第二引数のリストの要素に対する全ての参照・イテレータ無効化
--- splice(pos, x, it)は第二引数のリストのspliceされた要素の参照・イテレータ無効化
--- splice(pos, x, start, end)は第二引数のリストのspliceされた要素全ての参照・イテレータ無効化
- 連想コンテナ(set,map,multiset,multimap)
-- insert…イテレータ・参照ともに全て有効のまま
-- erase…削除された要素に対するイテレータ・参照のみ無効化
- 他
-- swapはイテレータ・参照は有効のままである
-- 上記以外でも内部で上記のメンバ関数がよばれれば同様の無効化がおきる
----

** テンプレートクラスをフレンドクラスにする
#codehighlight(C++){{

template&lt;typename T&gt; class hoge; // 前方宣言

class foo {
	template&lt;typename T&gt; friend class hoge; // フレンドクラスの宣言
};
}}

----

**効率のいいmapへの追加・更新

#codehighlight(C++){{

template &lt;class map_type, class key_type, class value_type&gt;
typename map_type::iterator efficientAddOrUpdate(map_type&amp; m, const key_type&amp; k, const value_type&amp; v)
{
	typename map_type::iterator lb = m.lower_bound(k);
	if(lb!=m.end() &amp;&amp; !(m.key_comp()(k, lb-&gt;first))) {
		// キーが存在した
		lb-&gt;second = v;
		return lb;
	} else {
		// キーが存在していない
		typedef typename map_type::value_type map_value_type;
		return m.insert(lb, map_value_type(k, v));
	}
}
}}

----

**モジュールを超えたメンバ関数呼び出し

他のモジュール(DLL)で生成したオブジェクトのメンバ関数を呼ぶ場合、
非仮想関数であれば呼び出し側の定義が、仮想関数であれば生成側の定義が呼ばれる。

ということは、モジュール間をまたいで文字列を渡したい場合、
publicな非仮想関数で文字列用のバッファを用意&amp;バッファからstringの生成を行い、
privateな純粋仮想関数でバッファに文字列を入れるようにすれば
バッファオーバーランとかの問題が防げるってことかな。

----    </description>
    <dc:date>2009-08-11T15:44:45+09:00</dc:date>
    <utime>1249973085</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/38.html">
    <title>文字コード</title>
    <link>https://w.atwiki.jp/mlnk/pages/38.html</link>
    <description>
      #include_js(http://www39.atwiki.jp/mlnk/?cmd=upload&amp;act=open&amp;page=%E6%96%87%E5%AD%97%E3%82%B3%E3%83%BC%E3%83%89&amp;file=ecl.js)
#include_js(http://www39.atwiki.jp/mlnk/?cmd=upload&amp;act=open&amp;page=%E6%96%87%E5%AD%97%E3%82%B3%E3%83%BC%E3%83%89&amp;file=encoding.js)

** 文字コード

画像の横軸が上位1バイト、縦軸が上位1バイト。

----

** CP932
Microsoft独自のShift_JIS拡張。~
シングルバイトは0x00～0x7Fおよび0xA1～0xDF。(unsigned char)((code^0x3F)-0xE0)&lt;0xBF~
第一バイトは0x81～0x9Fおよび0xE0～0xFC。(unsigned char)((code^0x20)-0xA1)&lt;=0x3B~
第二バイトは0x40～0x7Eおよび0x80～0xFC。((unsigned char)(code-0x40)&lt;=0xBC)&amp;&amp;(code!=0x7F)~


http://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP932.TXT

***CP932の文字コード分布

#html2(){{{{{{
&lt;a href=&quot;http://www39.atwiki.jp/mlnk/?cmd=upload&amp;act=open&amp;page=%E6%96%87%E5%AD%97%E3%82%B3%E3%83%BC%E3%83%89&amp;file=cp932_map.png&quot;&gt;&lt;img id=&quot;cp932&quot; src=&quot;http://www39.atwiki.jp/mlnk/?cmd=upload&amp;act=open&amp;page=%E6%96%87%E5%AD%97%E3%82%B3%E3%83%BC%E3%83%89&amp;file=cp932_map.png&quot; alt=&quot;CP932の文字コード分布&quot; /&gt;&lt;/a&gt;
}}}}}}

***CP932をUnicodeに変換した場合の文字コード分布

#html2(){{{{{{
&lt;a href=&quot;http://www39.atwiki.jp/mlnk/?cmd=upload&amp;act=open&amp;page=%E6%96%87%E5%AD%97%E3%82%B3%E3%83%BC%E3%83%89&amp;file=cp932_uni_map.png&quot;&gt;&lt;img id=&quot;cp932_unicode&quot; src=&quot;http://www39.atwiki.jp/mlnk/?cmd=upload&amp;act=open&amp;page=%E6%96%87%E5%AD%97%E3%82%B3%E3%83%BC%E3%83%89&amp;file=cp932_uni_map.png&quot; alt=&quot;CP932のUnicodeにおける文字コード分布&quot; /&gt;&lt;/a&gt;
}}}}}}


&amp;html(&lt;span id=&quot;encoding_tip&quot; style=&quot;padding:5px;background-color:#fff;position:absolute;border:2px solid black;left:0;top:0;display:none&quot;&gt;&lt;span id=&quot;encoding_position&quot;&gt;&lt;/span&gt;&lt;br /&gt;『&lt;span id=&quot;encoding_character&quot;&gt;&lt;/span&gt;』&lt;/span&gt;)



----    </description>
    <dc:date>2009-02-17T19:52:42+09:00</dc:date>
    <utime>1234867962</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/2.html">
    <title>メニュー</title>
    <link>https://w.atwiki.jp/mlnk/pages/2.html</link>
    <description>
      **メニュー
-[[トップページ]]
-[[C++]]
--[[仕様&gt;C++/仕様]]
--脱・標準Cライブラリ
---[[stdio.h&gt;C++/stdio.h]]
--[[Tips&gt;C++/tips]]
---[[Policyクラス&gt;C++/Policy]]
---[[初期化用クラス&gt;C++/初期化用クラス]]
--[[STL&gt;C++/STL]]
---[[ヘッダファイル&gt;C++/STL/ヘッダファイル]]
---[[string&gt;C++/STL/string]]
--ライブラリ
---[[mt_stream&gt;C++/ライブラリ/mt_stream]]
---[[multi_stream&gt;C++/ライブラリ/multi_stream]]
---[[ordered_pair&gt;C++/ライブラリ/ordered_pair]]
-[[Ajax]]
-[[HTML]]
-[[JavaScript]]
-[[MySQL]]
-[[PHP]]
--[[ライブラリ&gt;PHP/ライブラリ]]
---[[bind&gt;PHP/ライブラリ/bind]]
-[[Subversion]]
-[[Visual Studio]]
-[[文字コード]]
-[[略語]]
-[[作りたいもの]]

----

//**更新履歴
//#recent(20)

&amp;link_editmenu(text=ここを編集)    </description>
    <dc:date>2009-02-17T00:36:21+09:00</dc:date>
    <utime>1234798581</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/33.html">
    <title>C++/ライブラリ/mt_stream</title>
    <link>https://w.atwiki.jp/mlnk/pages/33.html</link>
    <description>
      ***概要
マルチスレッドでも出力の順番を保証する ostream ラッパークラス。~
ロック用にBoostを使ってるので要Boost。~
Boost使わずにロックできるならBoostなしでも可。

***使い方
#codehighlight(C++){{

util::mt_ostream mt(std::cout);

void multithreded_func()
{
	mt &lt;&lt; &quot;foo&quot; &lt;&lt; &quot;bar&quot; &lt;&lt; std::endl; // 出力が&quot;foobar&quot;になることを保証
}
}}

***コード
#codehighlight(C++){{
#ifndef UTIL_MT_STREAM_H
#define UTIL_MT_STREAM_H
 
#include &lt;iostream&gt;
 
#include &lt;boost/thread.hpp&gt;
 
namespace util {
 
namespace detail {
 
/* Boost を使用したロック用クラス */
class boost_lock {
public:
	boost_lock()
	{}
	~boost_lock()
	{}
	void lock()
	{
		mutex_.lock();
	}
	void unlock()
	{
		mutex_.unlock();
	}
private:
	explicit boost_lock(const boost_lock&amp;);
	boost_lock &amp;operator=(const boost_lock&amp;);
	boost::mutex mutex_;
};
 
/* 例外安全ロッククラス */
template&lt;class Lk&gt;
class lock_holder {
public:
	lock_holder(Lk &amp;lock)
		: lock_(lock)
	{
		lock_.lock();
	}
	~lock_holder()
	{
		try {
			lock_.unlock();
		} catch(...) {}
	}
private:
	explicit lock_holder(const lock_holder&amp;);
	lock_holder &amp;operator=(const lock_holder&amp;);
 
	Lk &amp;lock_;
};
 
/* Boostを使用したスレッド・ローカル・ストレージクラス */
template&lt;class Ch&gt;
class boost_thread_specific_storage {
public:
	boost_thread_specific_storage(size_t num)
		: default_size_(num)
	{}
 
	~boost_thread_specific_storage()
	{}
 
	Ch *begin()
	{
		return &amp;(get_storage()[0]);
	}
 
	void resize(size_t new_size)
	{
		get_storage().resize(new_size);
	}
 
	size_t size()
	{
		return get_storage().size();
	}
 
	void push_back(Ch c)
	{
		get_storage().push_back(c);
	}
	
	void clear()
	{
		get_storage().clear();
	}
 
private:
	std::vector&lt;Ch&gt; &amp;get_storage()
	{
		std::vector&lt;Ch&gt; *p = storage_.get();
		if(p==NULL) {
			p = new std::vector&lt;Ch&gt;;
			p-&gt;reserve(default_size_);
			storage_.reset(p);
		}
		return *p;
	}
 
	size_t default_size_;
	boost::thread_specific_ptr&lt;std::vector&lt;Ch&gt; &gt; storage_;
};
 
/* スレッドセーフなstreambufクラス */
template &lt;class Ch, class Lk, class St, class Tr=std::char_traits&lt;Ch&gt; &gt;
class basic_mt_streambuf : public std::basic_streambuf&lt;Ch,Tr&gt; {
public:
	typedef typename std::basic_streambuf&lt;Ch, Tr&gt;::int_type int_type;

	basic_mt_streambuf(std::basic_ostream&lt;Ch,Tr&gt;&amp; os)
		: out_(os), buf_(16)
	{}

	~basic_mt_streambuf()
	{}
	 
protected:
 
	int_type overflow(int_type c=Tr::eof())
	{
		if(c!=Tr::eof()) {
			buf_.push_back(c);
			return Tr::not_eof(c);
		}
		return Tr::eof();
	}
 
	int sync()
	{
		lock_holder&lt;Lk&gt; l(lock_);
		out_.write(buf_.begin(), buf_.size());
		out_.flush();
		buf_.clear();
		return 0;
	}
 
private:
	explicit basic_mt_streambuf(const basic_mt_streambuf&amp;);
	basic_mt_streambuf &amp;operator=(const basic_mt_streambuf&amp;);
 
    std::basic_ostream&lt;Ch,Tr&gt; &amp;out_;
	St buf_;
	Lk lock_;
};
 
/**
 ostreamのラッパークラス
 @param Ch 文字型(charまたはwchar_t)
 @param Lk 使用するロック用クラス
 @param St 使用するスレッド・ローカル・ストレージクラス
 @param Tr traitsクラス
 */
template &lt;class Ch, class Lk, class St, class Tr=std::char_traits&lt;Ch&gt; &gt;
class basic_mt_ostream : public std::basic_iostream&lt;Ch,Tr&gt; {
public:
	basic_mt_ostream(std::basic_ostream&lt;Ch,Tr&gt; &amp;os) 
		: std::basic_iostream&lt;Ch,Tr&gt;(&amp;streambuf_), streambuf_(os)
	{}
	~basic_mt_ostream()
	{}
 
private:
	explicit basic_mt_ostream(const basic_mt_ostream&amp;);
	basic_mt_ostream &amp;operator=(const basic_mt_ostream&amp;);
 
	basic_mt_streambuf&lt;Ch, Lk, St, Tr&gt; streambuf_;
};
 
}
 
typedef detail::basic_mt_ostream&lt;char, detail::boost_lock, detail::boost_thread_specific_storage&lt;char&gt; &gt; mt_ostream;
typedef detail::basic_mt_ostream&lt;wchar_t, detail::boost_lock, detail::boost_thread_specific_storage&lt;wchar_t&gt; &gt; mt_wostream;
 
}
 
#endif
}}    </description>
    <dc:date>2008-12-15T10:47:51+09:00</dc:date>
    <utime>1229305671</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/34.html">
    <title>C++/ライブラリ/multi_stream</title>
    <link>https://w.atwiki.jp/mlnk/pages/34.html</link>
    <description>
      ***概要
複数のostreamへ出力するストリームラッパクラス。~
コンストラクタの引数の展開にBoostを使ってるので要Boost。~
手書きすればBoostなしでも可。

***使い方
#codehighlight(C++){{

void func()
{
	std::ofstream of;
	of.open(&quot;somefile&quot;)
	util::multi_ostream(std::cout, of);
	mt &lt;&lt; &quot;foobar&quot; &lt;&lt; std::endl; // 標準出力とファイルに&quot;foobar&quot;が出力される
}
}}

***コード
#codehighlight(C++){{
/** @file multi_stream.h
 *  @breif 複数のostreamへ出力するストリームクラス
 */
#ifndef UTIL_MULTI_STREAM_H
#define UTIL_MULTI_STREAM_H

#include &lt;iostream&gt;
#include &lt;vector&gt;

#include &lt;boost/preprocessor.hpp&gt;

namespace util {

namespace detail {

//! コンストラクタで受け付けるostreamの最大数
#define ARGUMENT_MAX_COUNT 5

#define OSTREAM_ARRAY_ASSIGNMENT(z, n, data) outs_[n]=BOOST_PP_CAT(&amp;os, n);

#define BOOST_PP_LOCAL_MACRO(n) \
basic_multi_streambuf(BOOST_PP_ENUM_PARAMS(n, std::basic_ostream&lt;Ch BOOST_PP_COMMA() Tr&gt;&amp; os)) \
	: outs_(n), buf_(16) \
{ \
	setp(&amp;(buf_[0]), (&amp;(buf_[0])+buf_.size())); \
	BOOST_PP_REPEAT(n, OSTREAM_ARRAY_ASSIGNMENT, ~) \
}

#define BOOST_PP_LOCAL_LIMITS (1, BOOST_PP_EXPAND(ARGUMENT_MAX_COUNT)) 

/* 複数のostreamへ出力するためのstreambufクラス */
template &lt;class Ch, class Tr=std::char_traits&lt;Ch&gt; &gt;
class basic_multi_streambuf : public std::basic_streambuf&lt;Ch,Tr&gt; {
public:
	typedef typename std::basic_streambuf&lt;Ch, Tr&gt;::int_type int_type;

#include BOOST_PP_LOCAL_ITERATE()

	void add(std::basic_ostream&lt;Ch, Tr&gt;&amp; os)
	{
		outs_.push_back(&amp;os);
	}
	
	~basic_multi_streambuf()
	{}

protected:

	int_type overflow(int_type c=Tr::eof())
	{
		if(c!=Tr::eof()) {
			const size_t pos = pptr()-pbase();
			if(buf_.size() &lt;= pos+1) {
				buf_.resize(2*buf_.size());
				setp(&amp;(buf_[0]), (&amp;(buf_[0])+buf_.size()));
				pbump(pos);
			}
			*pptr() = Tr::to_char_type(c);
			pbump(1);
			return Tr::not_eof(c);
		}
		return Tr::eof();
	}

	int sync()
	{
		const size_t pos = pptr()-pbase();
		for(ostreams::iterator it=outs_.begin(); it!=outs_.end(); ++it) {
			(*it)-&gt;write(&amp;(buf_[0]), pos);
			(*it)-&gt;flush();
		}
		pbump(pbase()-pptr());
		return 0;
	}

private:
	explicit basic_multi_streambuf&lt;Ch, Tr&gt;(const basic_multi_streambuf&lt;Ch, Tr&gt;&amp;);
	basic_multi_streambuf&lt;Ch, Tr&gt; &amp;operator=(const basic_multi_streambuf&lt;Ch, Tr&gt;&amp;);

	typedef std::vector&lt;std::basic_ostream&lt;Ch,Tr&gt;* &gt; ostreams;
    ostreams outs_;
	std::vector&lt;Ch&gt; buf_;
};


#define BOOST_PP_LOCAL_MACRO(n) \
basic_multi_ostream(BOOST_PP_ENUM_PARAMS(n, std::basic_ostream&lt;Ch BOOST_PP_COMMA() Tr&gt;&amp; os)) \
	: std::basic_iostream&lt;Ch,Tr&gt;(&amp;streambuf_), streambuf_(BOOST_PP_ENUM_PARAMS(n, os)) \
{}

#define BOOST_PP_LOCAL_LIMITS (1, BOOST_PP_EXPAND(ARGUMENT_MAX_COUNT)) 

/* 複数のostreamへ出力するためのラッパークラス */
template &lt;class Ch, class Tr=std::char_traits&lt;Ch&gt; &gt;
class basic_multi_ostream : public std::basic_iostream&lt;Ch,Tr&gt; {
public:

#include BOOST_PP_LOCAL_ITERATE()

	~basic_multi_ostream()
	{}

	void add(std::basic_ostream&lt;Ch, Tr&gt;&amp; os)
	{
		streambuf_.add(os);
	}

private:
	explicit basic_multi_ostream(const basic_multi_ostream&amp;);
	basic_multi_ostream &amp;operator=(const basic_multi_ostream&amp;);

	basic_multi_streambuf&lt;Ch, Tr&gt; streambuf_;
};

}

typedef detail::basic_multi_ostream&lt;char&gt; multi_ostream;
typedef detail::basic_multi_ostream&lt;wchar_t&gt; multi_wostream;


#undef ARGUMENT_MAX_COUNT
#undef OSTREAM_ARRAY_ASSIGNMENT

}

#endif
}}    </description>
    <dc:date>2008-12-15T10:46:35+09:00</dc:date>
    <utime>1229305595</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/37.html">
    <title>C++/STL/ヘッダファイル</title>
    <link>https://w.atwiki.jp/mlnk/pages/37.html</link>
    <description>
      ** ヘッダファイル表
ヘッダーファイルを自己完結的にしよう。 by C++ Coding Standads

----

*** algorithm
|CENTER:|CENTER:|CENTER:|CENTER:|CENTER:|CENTER:|c
|find|find_if|find_end|find_first_of|for_each|adjacent_find|
|count|count_if|mismatch|equal|search|search_n|
|copy|copy_backward|swap|swap_ranges|iter_swap|transform|
|replace|replace_if|replace_copy|replace_copy_if|fill|fill_n|
|generate|generate_n|remove|remove_if|remove_copy|remove_copy_if|
|unique|unique_copy|reverse|reverse_copy|rotate|rotate_copy|
|random_shuffle|partition|stable_partition|sort|stable_sort|partial_sort|
|partial_sort_copy|nth_element|lower_bound|upper_bound|equal_range|binary_search|
|merge|inplace_merge|includes|set_union|set_intersection|set_difference|
|set_symmetric_difference|push_heap|pop_heap|make_heap|sort_heap|min|
|max|min_element|max_element|lexicographical_compare|next_permutation|prev_permutation|

----    </description>
    <dc:date>2008-12-14T14:24:50+09:00</dc:date>
    <utime>1229232290</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/27.html">
    <title>C++/STL</title>
    <link>https://w.atwiki.jp/mlnk/pages/27.html</link>
    <description>
      -[[ヘッダファイル&gt;C++/STL/ヘッダファイル]]
-[[string&gt;C++/STL/string]]

----    </description>
    <dc:date>2008-12-14T14:11:42+09:00</dc:date>
    <utime>1229231502</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/36.html">
    <title>c++/ライブラリ/ordered_pair</title>
    <link>https://w.atwiki.jp/mlnk/pages/36.html</link>
    <description>
      ***概要
firstのみで順序付けするpair。~
(std::pairはfirst、second両方で順序付けする)~
std::pairは非仮想デストラクタなんでポリモルフィックには扱えない。

***使い方
#codehighlight(C++){{

void ordered_pair_func()
{
	{
		std::pair&lt;int, int&gt; p1(10, 10), p2(20, 20), p3(10, 20);

		std::cout &lt;&lt; &quot;(10,10)&lt;(10,10)=&quot; &lt;&lt; (p1&lt;p1) &lt;&lt; std::endl;	// 0
		std::cout &lt;&lt; &quot;(10,10)&gt;(10,10)=&quot; &lt;&lt; (p1&gt;p1) &lt;&lt; std::endl;	// 0
		std::cout &lt;&lt; &quot;(10,10)&lt;(20,20)=&quot; &lt;&lt; (p1&lt;p2) &lt;&lt; std::endl;	// 1
		std::cout &lt;&lt; &quot;(10,10)&gt;(20,20)=&quot; &lt;&lt; (p1&gt;p2) &lt;&lt; std::endl;	// 0
		std::cout &lt;&lt; &quot;(10,10)&lt;(10,20)=&quot; &lt;&lt; (p1&lt;p3) &lt;&lt; std::endl;	// 1
		std::cout &lt;&lt; &quot;(10,10)&gt;(10,20)=&quot; &lt;&lt; (p1&gt;p3) &lt;&lt; std::endl;	// 0
	}
	std::cout &lt;&lt; std::endl;
	{
		ordered_pair&lt;int, int&gt; p1(10, 10), p2(20, 20), p3(10, 20);

		std::cout &lt;&lt; &quot;(10,10)&lt;(10,10)=&quot; &lt;&lt; (p1&lt;p1) &lt;&lt; std::endl;	// 0
		std::cout &lt;&lt; &quot;(10,10)&gt;(10,10)=&quot; &lt;&lt; (p1&gt;p1) &lt;&lt; std::endl;	// 0
		std::cout &lt;&lt; &quot;(10,10)&lt;(20,20)=&quot; &lt;&lt; (p1&lt;p2) &lt;&lt; std::endl;	// 1
		std::cout &lt;&lt; &quot;(10,10)&gt;(20,20)=&quot; &lt;&lt; (p1&gt;p2) &lt;&lt; std::endl;	// 0
		std::cout &lt;&lt; &quot;(10,10)&lt;(10,20)=&quot; &lt;&lt; (p1&lt;p3) &lt;&lt; std::endl;	// 0
		std::cout &lt;&lt; &quot;(10,10)&gt;(10,20)=&quot; &lt;&lt; (p1&gt;p3) &lt;&lt; std::endl;	// 0
	}
}
}}

***コード
#codehighlight(C++){{
#ifndef UTIL_ORDERED_PAIR_H
#define UTIL_ORDERED_PAIR_H
 
#include &lt;utility&gt;
 
namespace util {
 
template&lt;typename _Ty1, typename _Ty2&gt;
struct ordered_pair : std::pair&lt;_Ty1, _Ty2&gt;
{
	ordered_pair() : std::pair&lt;_Ty1, _Ty2&gt;(){}
	ordered_pair(const _Ty1&amp; _Val1, const _Ty2&amp; _Val2) : std::pair&lt;_Ty1, _Ty2&gt;(_Val1, _Val2) {}
	template&lt;typename _Other1, typename _Other2&gt; ordered_pair(const std::pair&lt;_Other1, _Other2&gt;&amp; _Right)
		: std::pair&lt;_Ty1, _Ty2&gt;(_Right)
	{}
};
 
 
template&lt;typename _Ty1, typename _Ty2&gt;
inline void swap(ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Left, ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Right)
{
	_Left.swap(_Right);
}
 
template&lt;typename _Ty1, typename _Ty2&gt;
inline bool operator==(const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Left, const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Right)
{
	return (_Left.first == _Right.first);
}
 
template&lt;typename _Ty1, typename _Ty2&gt;
inline bool operator!=(const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Left, const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Right)
{
	return (!(_Left == _Right));
}
 
template&lt;typename _Ty1, typename _Ty2&gt;
inline bool operator&lt;(const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Left, const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Right)
{
	return (_Left.first &lt; _Right.first);
}
 
template&lt;typename _Ty1, typename _Ty2&gt;
inline bool operator&gt;(const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Left, const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Right)
{
	return (_Right &lt; _Left);
}
 
template&lt;typename _Ty1, typename _Ty2&gt;
inline bool operator&lt;=(const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Left, const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Right)
{
	return (!(_Right &lt; _Left));
}
 
template&lt;typename _Ty1, typename _Ty2&gt;
inline bool operator&gt;=(const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Left, const ordered_pair&lt;_Ty1, _Ty2&gt;&amp; _Right)
{
	return (!(_Left &lt; _Right));
}
template&lt;typename _Ty1, typename _Ty2&gt;
inline ordered_pair&lt;_Ty1, _Ty2&gt; make_ordered_pair(_Ty1 _Val1, _Ty2 _Val2)
{
	return (ordered_pair&lt;_Ty1, _Ty2&gt;(_Val1, _Val2));
}
 
} //namespace util
 
#endif
}}    </description>
    <dc:date>2008-12-12T23:58:14+09:00</dc:date>
    <utime>1229093894</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/12.html">
    <title>C++</title>
    <link>https://w.atwiki.jp/mlnk/pages/12.html</link>
    <description>
      **[[仕様&gt;C++/仕様]]

**脱・標準Cライブラリ
-[[stdio.h&gt;C++/stdio.h]]

**[[Tips&gt;C++/tips]]
-[[Policyクラス&gt;C++/Policy]]
-[[初期化用クラス&gt;C++/初期化用クラス]]

**[[STL&gt;C++/STL]]
-[[string&gt;C++/STL/string]]

**ライブラリ
-[[mt_stream&gt;C++/ライブラリ/mt_stream]]
-[[multi_stream&gt;C++/ライブラリ/multi_stream]]

----    </description>
    <dc:date>2008-11-18T10:13:52+09:00</dc:date>
    <utime>1226970832</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/mlnk/pages/19.html">
    <title>作りたいもの</title>
    <link>https://w.atwiki.jp/mlnk/pages/19.html</link>
    <description>
      #contents

----
**HTMLのC++パーサクラス
-誰か作ってないんだろうか
-Boost.spiritを使って

----
**1つのコードでサーバーサイド、クライアントサイドでのバリデーションをするライブラリ
-サーバーサイドでルールを記述
-極力javascriptでそれを再現
-無理ならajax使ってサーバーサイドでバリデーション

----

**JavaScriptでPHPのserializeをエミュレート
-クライアントサイドから連想配列とかを渡してｳﾏｰ
-セキュリティ的にはどうなんだろ
--サーバーサイドで eval(送られてきたコード) はさすがにダメゼッタイ
--逆にクライアントサイドで eval(送られてきたコード) はまだましかと
-json_encodeで実現可?

----

** 二重に stripslashes しない magic_quote_gpc 対策
#codehighlight(PHP){{
function stripslashes_array($value)
{
    static magic_quoted = null;
    if(is_null(magic_quoted)) {
        magic_quoted = ini_get(&#039;magic_quotes_gpc&#039;);
    }

    if(magic_quoted) {
        $value = is_array($value) ? array_map(&#039;stripslashes_array&#039;, $value) : stripslashes($value);
    }
    return $value;
}

$_GET = stripslashes_array($_GET);
$_POST = stripslashes_array($_POST);
$_COOKIE = stripslashes_array($_COOKIE);
}}
- これだと複数回 stripslashes_array するとデータが壊れる
- strip済みを示す要素を入れる？(例: $_GET[&#039;striped&#039;]=true)
-- キーのコリジョンが怖い
-- 別の方法で strip しているところがあったら意味ない
- 結局 magic_quote_gpc を php.ini、.htaccess で解除するのが現実的かも

----
**マルチカラム用CSSジェネレータ
-基本定型文だからね

----
**CSSテンプレート
-なんか作ったときにぱっと見栄えを整えられるといい

----
**ajaxライブラリ
-id指定してそこに自動的に結果を書き込んだり
--上書き、追加を指定可能
-結果の連想配列のキーの要素に自動的に書き込んだり

----
**関数グラフの表示
-n^(1/2)とかどんなグラフだったっけ?

----    </description>
    <dc:date>2008-11-11T13:01:45+09:00</dc:date>
    <utime>1226376105</utime>
  </item>
  </rdf:RDF>
