<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Programming Collection</title><link>http://blogs.wankuma.com/hirase/category/1665.aspx</link><description>Programming Collection</description><managingEditor>T.Hirase</managingEditor><dc:language>ja-JP</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>T.Hirase</dc:creator><title>[VC] デバッグあり実行で、コンソールウィンドウが勝手に閉じる件</title><link>http://blogs.wankuma.com/hirase/archive/2009/08/21/180377.aspx</link><pubDate>Fri, 21 Aug 2009 19:12:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2009/08/21/180377.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/180377.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2009/08/21/180377.aspx#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/180377.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/180377.aspx</trackback:ping><description>&lt;pre class="c" xml:space="preserve" name="sourceCode"&gt;#include &amp;lt;windows.h&amp;gt;
int main()
{
  if ( IsDebuggerPresent() ) system("pause");
  return 0;
}&lt;/pre&gt;
&lt;p&gt;これで、デバッグ実行でも、デバッグなし実行でも、プログラム終了時に止まってくれる。&lt;/p&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/180377.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C#] Visual Studio アドインで新規ウィンドウを作成する。</title><link>http://blogs.wankuma.com/hirase/archive/2009/05/08/172559.aspx</link><pubDate>Fri, 08 May 2009 02:23:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2009/05/08/172559.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/172559.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2009/05/08/172559.aspx#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/172559.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/172559.aspx</trackback:ping><description>&lt;p&gt;参考：&lt;a href="http://msdn.microsoft.com/ja-jp/library/envdte80.windows2.createtoolwindow2.aspx"&gt;Windows2.CreateToolWindow2 メソッド &lt;/a&gt; (MSDN)&lt;/p&gt;
&lt;p&gt;メモでございます。&lt;/p&gt;
&lt;pre class="csharp" xml:space="preserve" name="sourceCode"&gt;public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
    handled = false;
    if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
    {
        if (commandName == "Sample.Connect.SampleWindow")
        {
            Windows2 windows = this._addInInstance.DTE.Windows as Windows2;
            if (windows == null)
                return;

            Assembly thisAssembly = Assembly.GetAssembly(this.GetType());
            object controlObject = null;
            Window window;
            window = windows.CreateToolWindow2(this._addInInstance, thisAssembly.Location, "Sample.MyUserControl", "Sample Window", "{374A85F2-DA7E-4ab0-8E0F-998E2FED0F55}", ref controlObject);
            if (window != null)
            {
                window.Visible = true;
            }
            handled = true;
            return;
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;あらかじめ、UserControl を継承した Sample.MyUserControl クラスを作っておく必要があります。&lt;/p&gt;
&lt;p&gt;このコードは、Visual Studio 2008 で生成したコードを元に追加したものです。&lt;/p&gt;
&lt;p&gt;以上&lt;/p&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/172559.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C#] ジェネリック＋型情報で頑張る「文字列→値」変換</title><link>http://blogs.wankuma.com/hirase/archive/2009/01/23/166655.aspx</link><pubDate>Fri, 23 Jan 2009 10:20:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2009/01/23/166655.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/166655.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2009/01/23/166655.aspx#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/166655.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/166655.aspx</trackback:ping><description>&lt;p&gt;Ｒ・田中一郎さんの「&lt;a href="http://blogs.wankuma.com/rti/archive/2009/01/22/166614.aspx"&gt;またジェネリックで挫折&lt;/a&gt;」しないように、ジェネリック＋型情報で頑張る日記。&lt;/p&gt;
&lt;pre class="csharp" xml:space="preserve" name="sourceCode"&gt;namespace Sample
{
    using System;
    using System.ComponentModel;
    using System.Diagnostics;

    static class Program
    {
        static void Main(string[] args)
        {
            var value = ToNumeric&amp;lt;Decimal&amp;gt;("10.2");
            Console.WriteLine(value);
        }

        static public T ToNumeric&amp;lt;T&amp;gt;(string value)
        {
            if (value == null) return default(T);

            if (String.IsNullOrEmpty(value)) return default(T);

            try
            {
                var converter = GetNumericConverter&amp;lt;T&amp;gt;();
                if (converter != null &amp;&amp; converter.CanConvertFrom(typeof(String)))
                {
                    return (T)converter.ConvertFromString(value);
                }
            }
            catch (Exception e)  // Exception を捕りたくないんだけど、他に方法がない。
            {
                Debug.WriteLine(e.Message);
            }
            return default(T);
        }

        static BaseNumberConverter GetNumericConverter&amp;lt;T&amp;gt;()
        {
            Type typeInfo = typeof(T);

            if (typeInfo == typeof(Byte)) return new ByteConverter();
            if (typeInfo == typeof(Decimal)) return new DecimalConverter();
            if (typeInfo == typeof(Double)) return new DoubleConverter();
            if (typeInfo == typeof(Int16)) return new Int16Converter();
            if (typeInfo == typeof(Int32)) return new Int32Converter();
            if (typeInfo == typeof(Int64)) return new Int64Converter();
            if (typeInfo == typeof(SByte)) return new SByteConverter();
            if (typeInfo == typeof(Single)) return new SingleConverter();
            if (typeInfo == typeof(UInt16)) return new UInt32Converter();
            if (typeInfo == typeof(UInt32)) return new UInt32Converter();
            if (typeInfo == typeof(UInt64)) return new UInt32Converter();

            return null;
        }
    }
}&lt;/pre&gt;

&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/166655.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>仕事のブログ更新</title><link>http://blogs.wankuma.com/hirase/archive/2008/12/09/163034.aspx</link><pubDate>Tue, 09 Dec 2008 09:35:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/12/09/163034.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/163034.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/12/09/163034.aspx#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/163034.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/163034.aspx</trackback:ping><description>&lt;p&gt;こんなの書きました↓&lt;/p&gt;
&lt;p&gt;CRIチャンネル「&lt;a href="http://ch.cri-mw.co.jp/hirase/52620.html"&gt;ミドルウェアにしてミドルウェアにあらず。&lt;/a&gt;」。&lt;/p&gt;
&lt;p&gt;よろしくどうぞ。&lt;/p&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/163034.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[HTML/CSS] もっとシンプルに定義リストdt ddを横並び</title><link>http://blogs.wankuma.com/hirase/archive/2008/07/19/149672.aspx</link><pubDate>Sat, 19 Jul 2008 00:28:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/07/19/149672.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/149672.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/07/19/149672.aspx#Feedback</comments><slash:comments>75</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/149672.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/149672.aspx</trackback:ping><description>&lt;p&gt;HTMLとCSSだけで、定義リスト（dt/dd）を横並びに表示するのは、結構面倒です。&lt;/p&gt;
&lt;p&gt;定義（dd）の方が固定長である必要があったりします。&lt;/p&gt;
&lt;p&gt;そんなこんなで、CSS2から追加された「display: table」を使ったシンプルな横並びの方法を実現してみました。&lt;/p&gt;
&lt;p&gt;&lt;ins&gt;下記のコードを参照される際は、必ずコメント欄もご参照ください。&lt;/ins&gt;&lt;/p&gt;
&lt;pre class="html" xml:space="preserve" name="sourceCode"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; ?&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Strict//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&amp;quot;&amp;gt;
&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; lang=&amp;quot;ja&amp;quot; xml:lang=&amp;quot;ja&amp;quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Simple Definition List&amp;lt;/title&amp;gt;
    &amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;
	dl        { display: table; }
	dl dt.row { display: table-row; }
	dl dt     { display: table-cell; padding-right: 0.4em; }
	dl dd     { display: table-cell; }
	&amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;dl&amp;gt;
        &amp;lt;dt class=&amp;quot;row&amp;quot; /&amp;gt;
        &amp;lt;dt&amp;gt;要勤務日数&amp;lt;/dt&amp;gt;&amp;lt;dd&amp;gt;20日&amp;lt;/dd&amp;gt;
        &amp;lt;dt class=&amp;quot;row&amp;quot; /&amp;gt;
        &amp;lt;dt&amp;gt;勤務時間&amp;lt;/dt&amp;gt;&amp;lt;dd&amp;gt;480時間&amp;lt;/dd&amp;gt;
    &amp;lt;/dl&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;対応ブラウザは、IE8、Firefox3、Saferi3 です。たぶん、Opera も行けます。&lt;/p&gt;
&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/149672.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C#] Google Protocol Buffers Serializer</title><link>http://blogs.wankuma.com/hirase/archive/2008/07/09/148170.aspx</link><pubDate>Wed, 09 Jul 2008 16:10:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/07/09/148170.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/148170.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/07/09/148170.aspx#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/148170.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/148170.aspx</trackback:ping><description>&lt;p&gt;&lt;a href="http://code.google.com/apis/protocolbuffers/"&gt;Google Protocol Buffers&lt;/a&gt;が公開されたとのことで、C#版のシリアライザ（仕様の確認はまた今度）を作ってみました。&lt;/p&gt;
&lt;pre class="csharp" xml:space="preserve" name="sourceCode"&gt;
namespace ProtocolBuffers
{
    using System;
    using System.IO;
    using System.Text;

    public class Serializer
    {
        #region Serialize
        public static void Serialize&amp;lt;TSerialize&amp;gt;(StreamWriter writer, TSerialize instance)
        {
            SerializeInternal(writer, instance.GetType(), instance, 0);
        }

        public static void Serialize(StreamWriter writer, Type type, Object instance)
        {
            SerializeInternal(writer, type, instance, 0);
        }

        private static void SerializeInternal(StreamWriter writer, Type type, Object instance, Int32 depth)
        {
            if (writer == null) throw new System.ArgumentNullException(&amp;quot;writer&amp;quot;);
            if (type == null) throw new System.ArgumentNullException(&amp;quot;type&amp;quot;);
            if (instance == null) throw new System.ArgumentNullException(&amp;quot;instance&amp;quot;);

            WriteIndent(writer, depth);
            writer.Write(type.Name);
            writer.WriteLine(&amp;quot;{&amp;quot;);
            foreach (var propertyInfo in type.GetProperties())
            {
                if (!propertyInfo.CanRead) continue;

                var propertyType = propertyInfo.PropertyType;
                var propertyName = propertyInfo.Name;
                var propertyValue = propertyInfo.GetValue(instance, null) ?? String.Empty;
                if (IsSystemType(propertyType))
                {
                    WriteIndent(writer, depth + 1);
                    writer.WriteLine(&amp;quot;{0} : \&amp;quot;{1}\&amp;quot;&amp;quot;, propertyName, propertyValue.ToString().Replace(&amp;quot;\&amp;quot;&amp;quot;, &amp;quot;\\\&amp;quot;&amp;quot;));
                }
                else
                {
                    SerializeInternal(writer, propertyType, propertyValue, depth + 1);
                }
            }
            WriteIndent(writer, depth);
            writer.WriteLine(&amp;quot;}&amp;quot;);
        }
        private static void WriteIndent(StreamWriter writer, Int32 depth)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(' ', depth);
            writer.Write(sb.ToString());
        }
        #endregion
        #region Utility
        private static Boolean IsSystemType(Type type)
        {
            return type.Namespace.StartsWith(&amp;quot;System&amp;quot;);
        }
        #endregion
    }
}
&lt;/pre&gt;
&lt;p&gt;使い方は、以下&lt;/p&gt;
&lt;pre class="csharp" xml:space="preserve" name="sourceCode"&gt;
namespace ProtocolBuffers
{
    using System;
    using System.IO;

    public class Test
    {
        public String Name { get; set; }
        public String EMail { get; set; }
    }

    public class Test2
    {
        public Test Test { get; set; }
        public Int32 Hash { get { return this.GetHashCode(); } }
        public DateTime DateTime { get { return DateTime.Now; } }
    }

    class TestProgram
    {
        static void Main(string[] args)
        {
            var testObject = new Test { Name = "Hirase", EMail = "hirase@example.com" };
            var test2Object = new Test2 { Test = testObject };
            using (var writer = new StreamWriter(@"test.pb"))
            {
                Serializer.Serialize&amp;lt;Test2&amp;gt;(writer, test2Object);
            }
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;結果は以下&lt;/p&gt;
&lt;pre&gt;
Test2{
 Test{
  Name : &amp;quot;Hirase&amp;quot;
  EMail : &amp;quot;hirase@example.com&amp;quot;
 }
 Hash : &amp;quot;54267293&amp;quot;
 DateTime : &amp;quot;2008/07/09 14:37:08&amp;quot;
}
&lt;/pre&gt;
&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/148170.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C++/CLI] アンマネージのコールバックにマネージのメソッドを登録する。</title><link>http://blogs.wankuma.com/hirase/archive/2008/06/09/142430.aspx</link><pubDate>Mon, 09 Jun 2008 21:34:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/06/09/142430.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/142430.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/06/09/142430.aspx#Feedback</comments><slash:comments>1050</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/142430.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/142430.aspx</trackback:ping><description>&lt;p&gt;こんな方法は・・・・・・・&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;using namespace System;

#pragma unmanaged
// コールバック関数の型
typedef int (__stdcall *CallbackFuncType)(int, float);

// コールバック関数
static CallbackFuncType g_func;

// コールバック関数の登録
void SetCallback(CallbackFuncType f)
{
    g_func = f;
}

// コールバック関数の呼び出し。
int Run()
{
    return g_func(10, 0.5f);
}
#pragma managed

int __stdcall MyFunc(int i, float f)
{
    Console::WriteLine(i.ToString());
    return static_cast&amp;lt;int&amp;gt;(i * f);
}

int main(array&amp;lt;System::String ^&amp;gt; ^args)
{
    // Callback登録（マネージ関数を登録・・）
    SetCallback(MyFunc);

    // GCしても大丈夫かを確認（登録した関数ポインタがGCされる・・ない）
    GC::Collect(2, GCCollectionMode::Forced);

    // コールバックをネイティブ関数に呼び出してもらう（GCされてたら死亡）
    Int32 ret = Run();
    Console::WriteLine(ret.ToString());

    return 0;
}
&lt;/pre&gt;
&lt;p&gt;これって、どうなんだろう。実行は問題ないんだけど。。&lt;/p&gt;
&lt;p&gt;MSDN「&lt;a href="http://msdn.microsoft.com/library/367eeye0.aspx"&gt;方法 : C++ Interop を使用してコールバックおよびデリゲートをマーシャリングする&lt;/a&gt;」とは違う方法で、&lt;a href="http://msdn.microsoft.com/library/system.runtime.interopservices.marshal.getfunctionpointerfordelegate.aspx"&gt;Marshal::GetFunctionPointerForDelegate()&lt;/a&gt; も使わないんだけど・・・。&lt;/p&gt;
&lt;p&gt;何かご存じの方、、ヘルプミー。&lt;/p&gt;
&lt;h3&gt;See Also&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=36275&amp;forum=7"&gt;[C#] デリゲートをGCの対象から外す方法&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/ja-JP/library/367eeye0.aspx"&gt;方法 : C++ Interop を使用してコールバックおよびデリゲートをマーシャリングする&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/367eeye0.aspx"&gt;How to: Marshal Callbacks and Delegates Using C++ Interop&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/142430.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C] wchar_tって・・・。</title><link>http://blogs.wankuma.com/hirase/archive/2008/05/27/139688.aspx</link><pubDate>Tue, 27 May 2008 22:37:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/05/27/139688.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/139688.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/05/27/139688.aspx#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/139688.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/139688.aspx</trackback:ping><description>&lt;p&gt;VC2008で、ソースファイルのプロパティで&lt;br&gt;
「詳細」の「コンパイル言語の選択」を「Cコードとしてコンパイル (/TC)」として、&lt;br&gt;
「言語」の「wchar_t をビルトイン型として扱う (/Zc:wchar_t」を「はい」にすると、&lt;br&gt;
wchar_t が組み込み型として使えそうなのに、使えないんですね・・・。&lt;br&gt;
&lt;br&gt;
# wchar.hをincludeすれば使えますけど、unsigned short扱いだし、&lt;br&gt;
# CRTを使いたくないのに、wchar.h から crtdefs.h を読み込んじゃうし・・・&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
C で書くなと？？&lt;br&gt;
&lt;/p&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/139688.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C++] シェーカーソート</title><link>http://blogs.wankuma.com/hirase/archive/2008/05/08/136788.aspx</link><pubDate>Thu, 08 May 2008 02:33:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/05/08/136788.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/136788.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/05/08/136788.aspx#Feedback</comments><slash:comments>32</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/136788.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/136788.aspx</trackback:ping><description>&lt;h2&gt;シェーカーソート（シェーカーソート、Shaker sort、カクテルソート、Cocktail sort、双方向バブルソート、bidirectional bubble sort）。&lt;/h2&gt;
&lt;p&gt;バブルソートの改良版。バブルソートで1回のループで昇順と降順を一度に並び替える。同じ要素の並びは変わらない安定ソート。&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;template &amp;lt;typename TElement, typename TSize&amp;gt;
void ShakerSort(TElement * data, const TSize size)
{
    TSize head = 0;
    TSize tail = size - 1;
    while (head &amp;lt; tail)
    {
        TSize swapPos = head;

        for (TSize i = head; i &amp;lt; tail; ++i)
        {
            TElement diff = data[i] - data[i+1];
            if (diff &amp;gt; 0)
            {
                data[i  ] = data[i+1];
                data[i+1] = diff + data[i];
                swapPos = i;
            }
        }

        tail = swapPos;

        for (TSize i = tail; i &amp;gt; head; --i)
        {
            TElement diff = data[i] - data[i+1];
            if (diff &amp;gt; 0)
            {
                data[i  ] = data[i+1];
                data[i+1] = diff + data[i];
                swapPos = i;
            }
        }
        {    // TSizeがunsigned型の場合、対策。
            TSize i = head;
            TElement diff = data[i] - data[i+1];
            if (diff &amp;gt; 0)
            {
                data[i  ] = data[i+1];
                data[i+1] = diff + data[i];
                swapPos = i;
            }
        }
        head = swapPos;
    }
}
&lt;/pre&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/136788.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C++] ハトの巣ソート</title><link>http://blogs.wankuma.com/hirase/archive/2008/05/08/136781.aspx</link><pubDate>Thu, 08 May 2008 01:37:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/05/08/136781.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/136781.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/05/08/136781.aspx#Feedback</comments><slash:comments>956</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/136781.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/136781.aspx</trackback:ping><description>&lt;h2&gt;ハトの巣ソート（ピジョンソート、Pigeon sort）。&lt;/h2&gt;
&lt;p&gt;いまいち理解できていないので、Wikipedia様に丸投げ→→「&lt;a href="http://en.wikipedia.org/wiki/Pigeonhole_sort" target="_blank"&gt;Pigeonhole sort&lt;/a&gt;」。（ 18:06, 19 March 2008版には擬似コードもあり。）&lt;/p&gt;
&lt;p&gt;メモリは食うけど、ソートは馬鹿早い。同じ要素の並びは変わらない安定ソート。&lt;/p&gt;
&lt;p&gt;追記＠2008-05-12T23:39+09:00：新しいバージョンをアップ。&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;/* データはユニークである必要があります。 */
template&amp;lt;typename TElement, typename TSize&amp;gt;
void PigeonholeSort(TElement * data, const TSize size)
{
    TElement min = data[0];
    TElement max = min;
    for (TSize i = 1; i &amp;lt; size; ++i) {
        min = data[i] &amp;lt; min ? data[i] : min;
        max = data[i] &amp;gt; max ? data[i] : max;
    }

    TSize range = max - min + 1;
    TElement * pigeonholes = new TElement[range];
    for (TSize i = 0; i &amp;lt; range; ++i)
        pigeonholes[i] = 0;	/* memsetで十分。 */

    for (TSize i = 0; i &amp;lt; size; ++i)
        pigeonholes[data[i]-min] = data[i];

    TSize dataPos = 0;
    for (TSize i = 0; i &amp;lt; range; ++i)
        if (pigeonholes[i] != 0)
            data[dataPos++] = i + min;

    delete[] pigeonholes;
}&lt;/pre&gt;
&lt;p&gt;追記@2008-05-08T17:19+09:00：下記のコードはちょっと間違えています。そのうち修正しますので、くれぐれも参考にしないよう、お願いします。&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;#include &amp;lt;map&amp;gt;
 
template&amp;lt;typename TElement, typename TSize&amp;gt;
void PigeonholeSort(TElement * data, const TSize size)
{
    typedef std::map&amp;lt;TElement, std::vector&amp;lt;TElement&amp;gt; &amp;gt; TMap;
    TMap pigeonholes;
    
    for (TSize i = 0; i &amp;lt; size; ++i)
        pigeonholes[data[i]].push_back(data[i]);
    
    TSize dataPos = 0;
    const TMap::const_iterator end = pigeonholes.end();
    for (TMap::iterator it = pigeonholes.begin(); it != end; ++it)
    {
        const TMap::value_type &amp; pigeonhole = *it;
        const TSize size =  pigeonhole.second.size();
        for (TSize i = 0; i &amp;lt; size; ++i)
        {
            data[dataPos++] = pigeonhole.first;
        }
    }
}
&lt;/pre&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/136781.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>