<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" 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/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 - Discussions by Burkholder</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/Burkholder/Discussions/RSS"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 - Discussions by Burkholder</title>
		<link>http://channel9.msdn.com/Niners/Burkholder/Discussions</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Niners/Burkholder/Discussions</link>
	<language>en</language>
	<pubDate>Sat, 18 May 2013 12:13:18 GMT</pubDate>
	<lastBuildDate>Sat, 18 May 2013 12:13:18 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>0</c9:totalResults>
	<c9:pageCount>0</c9:pageCount>
	<c9:pageSize>0</c9:pageSize>
	<item>
		<title>Tech Off - C++0x (vs2010) question, please tell me what i&#39;m doing wrong</title>
		<description><![CDATA[<p>@<a href="http://channel9.msdn.com/Forums/TechOff/C0x-vs2010-question-please-tell-me-what-im-doing-wrong#cafe07e108d9e4d4c91929e92013a3505">Mr Crash</a>: For your specific problem, I like Dexter's way better; however, since stuff like this pops up occassionally, here is another way:<pre class="brush: cpp">#include &lt;iostream&gt;
#include &lt;memory&gt;
#include &lt;functional&gt;

#include &lt;windows.h&gt;

using namespace std;

//=========================================================

/*
// Dexter's code:
template&lt;typename T&gt;  
class test_c { 
public:  
    explicit test_c(T p, std::function&lt;void(T)&gt; func)  
        : m_p(p), m_Func(func) { 
    }      
      
    ~test_c(void) {         
        m_Func(m_p); 
    } 
      
    T get(void) const {         
        return m_p; 
    } 
  
private:     
    T m_p; 
    const std::function&lt;void(T)&gt; m_Func; 
};
*/

// A dumbed-down version of the functors presented around
// page 110 of Modern C&#43;&#43; Design by Andrei Alexandrescu:
template &lt; typename RESULT_TYPE, typename PARAMETER_TYPE &gt;
class functor_base_t {
    public:
        virtual ~functor_base_t () {
            //
        }
        virtual RESULT_TYPE operator () ( PARAMETER_TYPE ) = 0;
};

template &lt; typename RESULT_TYPE, typename PARAMETER_TYPE, typename FUNCTOR &gt;
class functor_handler_t : public functor_base_t&lt; RESULT_TYPE, PARAMETER_TYPE &gt; {
    FUNCTOR m_functor;
    public:
        functor_handler_t ( FUNCTOR functor ) : m_functor( functor ) {
            //
        }
        virtual ~functor_handler_t () {
            //
        }
        virtual RESULT_TYPE operator () ( PARAMETER_TYPE parameter ) {
            return m_functor( parameter );
        }
};

template &lt; typename TYPE &gt;
class test_c {
    private:
        typedef void RESULT_TYPE;
        typedef TYPE PARAMETER_TYPE;

        PARAMETER_TYPE m_parameter;
        std::shared_ptr&lt; functor_base_t&lt; RESULT_TYPE, PARAMETER_TYPE &gt; &gt; m_functor_handler;
    public:
        template &lt; typename FUNCTOR &gt;
        explicit test_c ( PARAMETER_TYPE parameter, FUNCTOR functor ) :
            m_parameter( parameter ),
            m_functor_handler(
                new functor_handler_t&lt;
                    RESULT_TYPE,
                    PARAMETER_TYPE,
                    FUNCTOR
                &gt;( functor )
            )
        {
            //
        }
        ~test_c () {
            ( *m_functor_handler )( m_parameter );
        }
        PARAMETER_TYPE const &amp; get () const {
            return m_parameter;
        }
};

//=========================================================

inline void normal_func ( int p ) {
    cout &lt;&lt; &quot;p: &quot; &lt;&lt; p &lt;&lt; endl;
}

struct normal_struct_func {
    inline void operator() (int p) const {
        cout &lt;&lt; &quot;p: &quot; &lt;&lt; p &lt;&lt; endl;
    }
};

template&lt; typename T, typename Function &gt;
inline void test_f ( T p, Function func ) {
    func( p );
}

int main () {
    // test_f tests
    test_f( 11, [] ( int p ) { cout &lt;&lt; &quot;p: &quot; &lt;&lt; p &lt;&lt; endl; } );
    test_f( 22, normal_func );
    test_f( 33, normal_struct_func() );

    // test_c tests
    test_c&lt; int &gt; tc1( 11, [] ( int p ) { cout &lt;&lt; &quot;p: &quot; &lt;&lt; p &lt;&lt; endl; } );
    test_c&lt; int &gt; tc2( 22, normal_func );
    test_c&lt; int &gt; tc3( 33, normal_struct_func() );

    test_c&lt; int * &gt; tc4(
        new int,
        [] ( int * ptr ) {
            cout &lt;&lt; &quot;tc4: &quot; &lt;&lt; *ptr &lt;&lt; endl;
            delete ptr;
        }
    );
    *tc4.get() = 44;
    test_c&lt; int * &gt; tc5(
        new int[ 3 ],
        [] ( int * arr ) {
            int const * i = &amp;arr[ 0 ];
            int const * end = &amp;arr[ 3 ];
            cout &lt;&lt; &quot;tc5: { &quot;;
            if ( i != end ) {
                cout &lt;&lt; *i;
                for ( &#43;&#43;i ; i != end; &#43;&#43;i )
                    cout &lt;&lt; &quot;, &quot; &lt;&lt; *i;
            }
            cout &lt;&lt; &quot; }&quot; &lt;&lt; endl;
            delete[] arr;
        }
    );
    tc5.get()[ 0 ] = 55;
    tc5.get()[ 1 ] = 56;
    tc5.get()[ 2 ] = 57;

#define scoped test_c

    // 1:
    scoped&lt;HMODULE&gt; dll(LoadLibraryA(&quot;kernel32.dll&quot;), [](HMODULE h){FreeLibrary(h);});

    // 2:
    scoped&lt;int*&gt; ptr2(new int, [](int *p){delete p;});

    // 3:
    scoped&lt;int*&gt; ptr3(new int[100], [](int *p){delete[] p;});

    // 4:
    scoped&lt;int&gt; ptr4(1974, [](int p){ cout &lt;&lt; p &lt;&lt; endl;});

    return 0;
}
</pre>This works in VC&#43;&#43;2010 and MinGW's port of g&#43;&#43; 4.5.2.&nbsp; Here's the command line for MinGW's g&#43;&#43; 4.5.2:<pre class="brush: text">g&#43;&#43; -o main.exe main.cpp -std=c&#43;&#43;0x -march=native -O3 -Wall -Wextra -Werror</pre>This code produces the following output:<pre class="brush: text">p: 11
p: 22
p: 33
1974
tc5: { 55, 56, 57 }
tc4: 44
p: 33
p: 22
p: 11</pre></p><p>Hope This Also Helps,<br>Joshua Burkholder</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/C0x-vs2010-question-please-tell-me-what-im-doing-wrong/63f29a96a5a2412db9de9e93000ed124#63f29a96a5a2412db9de9e93000ed124</link>
		<pubDate>Wed, 23 Feb 2011 00:53:56 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/C0x-vs2010-question-please-tell-me-what-im-doing-wrong/63f29a96a5a2412db9de9e93000ed124#63f29a96a5a2412db9de9e93000ed124</guid>
		<dc:creator>Joshua Burkholder</dc:creator>
		<slash:comments>34</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Burkholder/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>