<?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>Comment Feed for devcodex</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/devcodex/Comments/RSS"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>devcodex</title>
		<link></link>
	</image>
	<description></description>
	<link></link>
	<language>en</language>
	<pubDate>Sat, 18 May 2013 18:01:23 GMT</pubDate>
	<lastBuildDate>Sat, 18 May 2013 18:01:23 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<item>
		<title>Re: C++ and Beyond 2012: Scott Meyers - Universal References in C++11</title>
		<description>
			<![CDATA[<p>This video and the related ACCU article are both great and really have given me a lot to think of on this topic, it has clarified a number of issues and questions I've had working with &amp;&amp; in my own code. Thanks Scott for giving the talk and allowing it to be shown on Channel 9 for those of us who couldn't be at the even and thanks to Charles for capturing it and getting it posted for us!</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Scott-Meyers-Universal-References-in-Cpp11#c634854522310366094</link>
		<pubDate>Wed, 10 Oct 2012 07:50:31 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Scott-Meyers-Universal-References-in-Cpp11#c634854522310366094</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: GoingNative 8: Introducing Casablanca - A Modern C++ API for Connected Computing</title>
		<description>
			<![CDATA[<p>This is amazing, I have been toying around with a pet project that interacts with several REST/JSON &nbsp;based API's and seriously feeling the lack of a good library for this type of work in native c&#43;&#43;. This is the type of effort that I've been looking forward to and I can't wait to start playing with it.</p><p>@Charles Good job on the solo mission man, this was a great ep!</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-8-Introducing-Casablanca-A-Modern-C-API-for-Connected-Computing#c634714400656850064</link>
		<pubDate>Tue, 01 May 2012 03:34:25 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-8-Introducing-Casablanca-A-Modern-C-API-for-Connected-Computing#c634714400656850064</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: GoingNative 4: Jim Springfield on ATL, GoingNative Conference - Register Today!</title>
		<description>
			<![CDATA[<p>@<a href="/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634587712651207501">Raanen</a>:It's not that I take offense but &quot;can't even imagine&quot; is a figure of speech. The scope of windows/visual studio is much bigger than anything I've worked on and I know just how much work its been in my own projects to maintain backwards compatibility, sometimes its just time to draw the line in the sand.</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634587807987001428</link>
		<pubDate>Tue, 06 Dec 2011 15:06:38 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634587807987001428</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: GoingNative 4: Jim Springfield on ATL, GoingNative Conference - Register Today!</title>
		<description>
			<![CDATA[<p>@<a href="/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634587259426445648">JimSpringfield</a>: Thanks for taking the time to stop by and give an explanation. I can't even imagine how much goes into building and supporting these new API's and at some point it's understandable that a line has to be drawn on how much backwards compatibility you can manage and still get the product finished on time.</p><p>As you mentioned you're not dropping support for VC10, that's the toolset you want to use to target XP. For the product I'm working on the current plan is to switch to a maintenance support around the time Windows 8 arrives (much as XP is already in maintenance support only). New product versions will target newer versions of Windows. I mean seriously at some point there has to be a&nbsp;transition&nbsp;and lets be honest, there really aren't a whole lot of new features in VC11 that can't already be found in libraries such as Boost. It makes sense transition now and the above plan is a fairly painless one.</p><p>&nbsp;@<a href="/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634587466873513429">Raanen</a>:You mention using LoadLibrary and make it sound like it's just going to take a few lines. How do you know that's all that's involved? If that really is the case then take a look again at what Jim said, specifically:</p><p></p><blockquote><div class="quoteText"><p></p><p>Note that sometimes, even if we don't officially support it, DLLs may load on an older OS or you may be able to statically link the CRT and avoid the new APIs or even implement your own version of the new API.</p><p></p></div></blockquote><p></p><p>If using LoadLibrary or something along those lines is as simple as you say it is the above appears to me to be an invitation for you to make it happen. I'm interested to see if the above is possible and will be testing it myself, I will post back with any findings. Before you throw in the towel, especially for something you consider to be easy, lets try and see if there are working alternatives, albeit unofficially supported.</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634587600554096582</link>
		<pubDate>Tue, 06 Dec 2011 09:20:55 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634587600554096582</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: GoingNative 4: Jim Springfield on ATL, GoingNative Conference - Register Today!</title>
		<description>
			<![CDATA[<p>You guys I understand the frustration here and while I don't exactly agree with everyone's logic on the matter I do think you guys deserve a technical answer on why XP is no longer supported. On the other-hand you've been asked more than once to keep on topic in these GoingNative threads, with that in mind I've opened up a forum post on the matter and also quoted Bernd from above as I think his is the most rational explanation of why XP support is still needed.</p><p><a href="http://channel9.msdn.com/Forums/TechOff/A-question-on-XP-support-in-VC11">http&#58;&#47;&#47;channel9.msdn.com&#47;Forums&#47;TechOff&#47;A-question-on-XP-support-in-VC11</a></p><p>Charles, if the discussion gets moved there can you help us out and try and get someone to drop by and give a technical clarification for the decision? Thanks man, and keep up the great work on GoingNative.</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634587193180718487</link>
		<pubDate>Mon, 05 Dec 2011 22:01:58 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634587193180718487</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: GoingNative 4: Jim Springfield on ATL, GoingNative Conference - Register Today!</title>
		<description>
			<![CDATA[<p>@felix9 I spent a good chunk of time earlier today on that same path (ASCII C '67') but the closest I came was adding the ascii C and &#43; values (so &quot;C&quot; &#43; &quot;&#43;&quot;) but that only got me to 110.</p><p>Great job to the winners!</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634582168474145546</link>
		<pubDate>Wed, 30 Nov 2011 02:27:27 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634582168474145546</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: GoingNative 4: Jim Springfield on ATL, GoingNative Conference - Register Today!</title>
		<description>
			<![CDATA[<p>@felix9 That's a great answer man!</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634581165765970922</link>
		<pubDate>Mon, 28 Nov 2011 22:36:16 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634581165765970922</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: GoingNative 4: Jim Springfield on ATL, GoingNative Conference - Register Today!</title>
		<description>
			<![CDATA[<p>@STL Thanks for the detailed explanation of the situation as well as a very simple workaround.</p><p>I'm inclined to agree with the decision to keep infinity=5 given how easy it is to regain previous functionality when needed.&nbsp;</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634580462850549011</link>
		<pubDate>Mon, 28 Nov 2011 03:04:45 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634580462850549011</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: GoingNative 4: Jim Springfield on ATL, GoingNative Conference - Register Today!</title>
		<description>
			<![CDATA[<p>My guess for the $112 pricetag is C&#43;&#43; 11 and the month of the event, February (the 2nd month): 112</p><p>My other guess would be this is the first (of many) C&#43;&#43; events in 20(12): 112</p><p>Great episode!</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634578049127599227</link>
		<pubDate>Fri, 25 Nov 2011 08:01:52 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634578049127599227</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: GoingNative 4: Jim Springfield on ATL, GoingNative Conference - Register Today!</title>
		<description>
			<![CDATA[<p>@Charles Don't listen to the naysayers man, there is so much new (good) C&#43;&#43; content to consume around here than anywhere else and I have a sneaking suspicion your enthusiasm is at the root of a lot of it.</p><p>I have registered for my seat for the show and I can't wait to get out there and meet all these great people who are putting it on!</p><p>@tgoodhew I'm loving Visual Studio 11 so far, I am running into an issue however that is making it difficult to port many of my existing projects over. While I understand variadic templates won't be making it into the initial release is there any chance that we can the current &quot;infinity&quot; for the faked variadic templates back to 10 from the current 5?</p><p>I ask because one particular dependency, googletest, makes use of tuples and currently breaks as it exceeds the limit of 5 elements (but does keep under the limit of 10).</p><p>Thanks again!</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634577805466323779</link>
		<pubDate>Fri, 25 Nov 2011 01:15:46 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-4-Jim-Springfield-on-ATL-GoingNative-Conference-Register-Today#c634577805466323779</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: C9 Lectures: Stephan T. Lavavej - Standard Template Library (STL), 10 of 10</title>
		<description>
			<![CDATA[ <p>I watched through this episode again and felt like I came away with much more this time around. After taking another stab at this I think I have an improved solution that addresses each of the suggestion points you provided. I wasn't certain how to handle the conversion of signed to unsigned while in a template scenario like this, but with a little digging I found the STL has something for that too. Thanks again!</p><p><pre class="brush: cpp">#include &lt;cstdint&gt;
#include &lt;iostream&gt;
#include &lt;type_traits&gt;

namespace anh {

    namespace detail {

        template&lt;typename T&gt;
        T swap_endian_(T value, std::integral_constant&lt;size_t, 1&gt;) {
            return value;
        }

        template&lt;typename T&gt;
        T swap_endian_(T value, std::integral_constant&lt;size_t, 2&gt;) {
            std::make_unsigned&lt;T&gt;::type&amp; tmp = static_cast&lt;std::make_unsigned&lt;T&gt;::type&amp;&gt;(value);
            tmp = (tmp &gt;&gt; 8) | (tmp &lt;&lt; 8);

            return value;
        }
        
        template&lt;typename T&gt;
        T swap_endian_(T value, std::integral_constant&lt;size_t, 4&gt;) {
            std::make_unsigned&lt;T&gt;::type&amp; tmp = static_cast&lt;std::make_unsigned&lt;T&gt;::type&amp;&gt;(value);
            tmp = (tmp &gt;&gt; 24) |
                   ((tmp &amp; 0x00FF0000) &gt;&gt; 8) | ((tmp &amp; 0x0000FF00) &lt;&lt; 8) |
                   (tmp &lt;&lt; 24);

            return value;
        }
        
        template&lt;typename T&gt;
        T swap_endian_(T value, std::integral_constant&lt;size_t, 8&gt;) {
            std::make_unsigned&lt;T&gt;::type&amp; tmp = static_cast&lt;std::make_unsigned&lt;T&gt;::type&amp;&gt;(value);
            tmp = (tmp &gt;&gt; 56) |
                ((tmp &amp; 0x00FF000000000000ULL) &gt;&gt; 40) |
                ((tmp &amp; 0x0000FF0000000000ULL) &gt;&gt; 24) |
                ((tmp &amp; 0x000000FF00000000ULL) &gt;&gt; 8)  |
                ((tmp &amp; 0x00000000FF000000ULL) &lt;&lt; 8)  |
                ((tmp &amp; 0x0000000000FF0000ULL) &lt;&lt; 24) |
                ((tmp &amp; 0x000000000000FF00ULL) &lt;&lt; 40) |
                (tmp  &lt;&lt; 56);

            return value;
        }
    }

    /*! Swaps the endianness of integral values and returns the results.
    *
    * \param value An integral value for which to swap the endianness.
    * \return A copy of the input parameter with its endianness swapped.
    */
    template&lt;typename T&gt;
    T swap_endian(T value) {
        static_assert(std::is_integral&lt;int&gt;::value, &quot;swap_endian&lt;T&gt; requires T to be an integral type.&quot;);
        return detail::swap_endian_&lt;T&gt;(value, std::integral_constant&lt;size_t, sizeof(T)&gt;());
    }

}  // namespace anh

using namespace std;

int main() {
    uint32_t test_uint_hostbyte = 0x00000002;
    uint32_t test_uint_netbyte = 0x02000000;

    uint32_t tmp_uint = anh::swap_endian(test_uint_hostbyte);

    if (tmp_uint == test_uint_netbyte) {
        cout &lt;&lt; &quot;Can swap 32-bit unsigned types\n&quot;;
    } else {
        cout &lt;&lt; &quot;Swapping 32-bit unsigned types failed\n&quot;;
    }

    int32_t test_int_hostbyte = 0xfffffff5;  // -11 on two's complement machines
    int32_t test_int_netbyte = 0xf5ffffff;

    if (tmp_uint == test_uint_netbyte) {
        cout &lt;&lt; &quot;Can swap 32-bit signed types\n&quot;;
    } else {
        cout &lt;&lt; &quot;Swapping 32-bit signed types failed\n&quot;;
    }

    return 0;
}</pre></p><p>&nbsp;</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-10-of-10#c634318873170000000</link>
		<pubDate>Sat, 29 Jan 2011 08:41:57 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-10-of-10#c634318873170000000</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: C9 Lectures: Stephan T. Lavavej - Standard Template Library (STL), 10 of 10</title>
		<description>
			<![CDATA[ <p>@STL</p><p>Thank you for the excellent feedback. In this particular case the Winsock htonl and similar functions to my knowledge don't work directly on 64-bit types, which is a need for several of the proprietary data packet formats that the project I'm currently working on deals with.</p><p>I am humbled again by just how much there is already provided with the STL and how much I still have to learn <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif?v=c9' alt='Smiley' /> Thanks again!</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-10-of-10#c634317525660000000</link>
		<pubDate>Thu, 27 Jan 2011 19:16:06 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-10-of-10#c634317525660000000</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: C9 Lectures: Stephan T. Lavavej - Standard Template Library (STL), 10 of 10</title>
		<description>
			<![CDATA[ <p>Hi STL,</p><p>This was another great episode and I'm looking forward to the new series! I've learned a great deal from the whole series and it's had a significant impact on the code I write. Thanks for all the effort you put into this!</p><p>I was just working on a bit of code necessary for converting endianness when dealing with integer types in network code. Having recently watched this episode and remembering your solution presented in episode 3 for containers I put together this solution, I'm sure it's not perfect but thanks to these shows I feel it's a much more robust and flexible solution than what I would have come up with in the past.</p><p><pre class="brush: cpp">#include &lt;cstdint&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;limits&gt;

namespace anh {

    namespace detail {
        /// @TODO Remove quotes from around constexpr when visual studio begins
        /// supporting that c&#43;&#43;0x feature.
        /*constexpr*/ bool inline is_big_endian() {
            uint16_t x = 1;
            return !(*reinterpret_cast&lt;char*&gt;(&amp;x));
        }

        struct bit8_tag{};
        struct bit16_tag{};
        struct bit32_tag{};
        struct bit64_tag{};

        template&lt;typename T&gt; struct integer_traits;
        
        template&lt;&gt;
        struct integer_traits&lt;int8_t&gt; {
            typedef bit8_tag category;
        };
        
        template&lt;&gt;
        struct integer_traits&lt;uint8_t&gt; {
            typedef bit8_tag category;
        };
        
        template&lt;&gt;
        struct integer_traits&lt;int16_t&gt; {
            typedef bit16_tag category;
        };
        
        template&lt;&gt;
        struct integer_traits&lt;uint16_t&gt; {
            typedef bit16_tag category;
        };
        
        template&lt;&gt;
        struct integer_traits&lt;int32_t&gt; {
            typedef bit32_tag category;
        };
        
        template&lt;&gt;
        struct integer_traits&lt;uint32_t&gt; {
            typedef bit32_tag category;
        };
        
        template&lt;&gt;
        struct integer_traits&lt;int64_t&gt; {
            typedef bit64_tag category;
        };
        
        template&lt;&gt;
        struct integer_traits&lt;uint64_t&gt; {
            typedef bit64_tag category;
        };
        
        template&lt;typename T&gt;
        T swap_endian_(T value, bit8_tag) {
            return value;
        }

        template&lt;typename T&gt;
        T swap_endian_(T value, bit16_tag) {
            return (value &gt;&gt; 8) | (value &lt;&lt; 8);
        }
        
        template&lt;typename T&gt;
        T swap_endian_(T value, bit32_tag) {
            return (value &gt;&gt; 24) |
                ((value &amp; 0x00FF0000) &gt;&gt; 8) | ((value &amp; 0x0000FF00) &lt;&lt; 8) |
                (value &lt;&lt; 24);
        }
        
        template&lt;typename T&gt;
        T swap_endian_(T value, bit64_tag) {
            return (value  &gt;&gt; 56) |
            #ifdef _WIN32
                ((value &amp; 0x00FF000000000000) &gt;&gt; 40) |
                ((value &amp; 0x0000FF0000000000) &gt;&gt; 24) |
                ((value &amp; 0x000000FF00000000) &gt;&gt; 8)  |
                ((value &amp; 0x00000000FF000000) &lt;&lt; 8)  |
                ((value &amp; 0x0000000000FF0000) &lt;&lt; 24) |
                ((value &amp; 0x000000000000FF00) &lt;&lt; 40) |
            #else
                ((value &amp; 0x00FF000000000000LLU) &gt;&gt; 40) |
                ((value &amp; 0x0000FF0000000000LLU) &gt;&gt; 24) |
                ((value &amp; 0x000000FF00000000LLU) &gt;&gt; 8)  |
                ((value &amp; 0x00000000FF000000LLU) &lt;&lt; 8)  |
                ((value &amp; 0x0000000000FF0000LLU) &lt;&lt; 24) |
                ((value &amp; 0x000000000000FF00LLU) &lt;&lt; 40) |
            #endif
            (value  &lt;&lt; 56);
        }
    }

    /*! Swaps the endianness of the passed in value and returns the results.
    *
    * For standard integer types (any of the intX_t/uintX_t types)
    * specializations exist to ensure the fastest performance. All other types
    * are treated as char* and reversed.
    */
    template&lt;typename T&gt; 
    T swap_endian(T value) {
        if (std::numeric_limits&lt;T&gt;::is_integer) {
            return detail::swap_endian_&lt;T&gt;(value, detail::integer_traits&lt;T&gt;::category());
        }

        unsigned char* tmp = reinterpret_cast&lt;unsigned char*&gt;(&amp;value);
        std::reverse(tmp, tmp &#43; sizeof(T));
        return value;
    }

    /*! Converts a value from host-byte order to little endian.
    *
    * Only works with integer types.
    *
    * \param value The value to convert to little endian
    * \return The value converted to endian order.
    */
    template&lt;typename T&gt;
    T host_to_little(T value) {
        static_assert(std::numeric_limits&lt;T&gt;::is_integer);
        return detail::is_big_endian() ? swap_endian(value) : value;
    }
    
    /*! Converts a value from host-byte order to big endian.
    *
    * Only works with integer types.
    *
    * \param value The value to convert to big endian
    * \return The value converted to endian order.
    */
    template&lt;typename T&gt;
    T host_to_big(T value) {
        static_assert(std::numeric_limits&lt;T&gt;::is_integer);
        return detail::is_big_endian() ? value : swap_endian(value);
    }
    
    /*! Converts a value from big endian to host-byte order.
    *
    * Only works with integer types.
    *
    * \param value The value to convert to host-byte order.
    * \return The value converted to host-byte order.
    */
    template&lt;typename T&gt;
    T big_to_host(T value) {
        static_assert(std::numeric_limits&lt;T&gt;::is_integer);
        return detail::is_big_endian() ? value : swap_endian(value);
    }
    
    /*! Converts a value from little endian to host-byte order.
    *
    * Only works with integer types.
    *
    * \param value The value to convert to host-byte order.
    * \return The value converted to host-byte order.
    */
    template&lt;typename T&gt;
    T little_to_host(T value) {
        static_assert(std::numeric_limits&lt;T&gt;::is_integer);
        return detail::is_big_endian() ? swap_endian(value) : value;
    }
        
}  // namespace anh


using namespace std;

int main() {   
    uint32_t test_int_hostbyte = 0x00000002;
    uint32_t test_int_netbyte = 0x02000000;

    uint32_t tmp_int = anh::swap_endian(test_int_hostbyte);

    if (tmp_int == test_int_netbyte) {
        cout &lt;&lt; &quot;Hurray, swapping works!\n&quot;;
    } else {
        cout &lt;&lt; &quot;Sorry, try again!\n&quot;;
    }

    return 0;
}</pre></p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-10-of-10#c634316300780000000</link>
		<pubDate>Wed, 26 Jan 2011 09:14:38 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-10-of-10#c634316300780000000</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: C9 Lectures: Stephan T. Lavavej - Standard Template Library (STL), 6 of n</title>
		<description>
			<![CDATA[ <p>@STL</p><p>Thank you for the feedback! Here's the updated working solution (in roughly half the amount of code as my first attempt and less than a third of that of the original legacy code):</p><p><pre class="brush: cpp">std::u16string chat_data = message-&gt;getStringUnicode16();
std::wstring tmp(chat_data.begin(), chat_data.end());

const std::wregex p(L&quot;(\\d&#43;) (\\d&#43;) (\\d&#43;) (\\d&#43;) (\\d&#43;) (.*)&quot;);
std::wsmatch m;

if (! std::regex_match(tmp, m, p)) {
    LOG(ERROR) &lt;&lt; &quot;Invalid spatial chat message format&quot;;
    return;
}</pre></p><p>Looking at this solution compared to the original while loop that did the same thing it's much easier now to determine the intention of the code just by reading it. I am continually amazed at just how powerful and elegant the stl is and at the impact the new standard has on the language, what an awesome experience it must be to have a career working so closely with it!</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-6-of-n#c634230825960000000</link>
		<pubDate>Tue, 19 Oct 2010 10:56:36 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-6-of-n#c634230825960000000</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
	<item>
		<title>Re: C9 Lectures: Stephan T. Lavavej - Standard Template Library (STL), 6 of n</title>
		<description>
			<![CDATA[ <p>Hi STL,</p><p>First I just want to say I've been following these videos since they started and I love them, you have a natural knack for disseminating quality information <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></p><p>It just so happened that as I was watching this video I was also working on an old and nefarious piece of code: A network message that is essentially a string in char16_t* format that contains 5 integers, formatted as strings and separated by spaces, followed by a text message (this is actually a network message for SpatialChat in the MMORPG project I'm working on). The 5 integers at the beginning are id's for things such as the mood of the speaker, the form of delivery (shouting, whispering, etc).</p><p>The original implementation of this involved converting a char16_t* string to a int8_t* (or from utf16 to utf8) before trying to work its way through processing and then converting back to char16_t*. This works great for English text but we recently had a few players from Russia using the Cyrillic alphabet in which the code blows up due to the loss of precision in switching between string formats. It was my task to resolve this issue and given that the bulk of the processing is in a while loop I wanted to see if this could be eliminated using STL algorithms.</p><p>Here is the original code as it existed in the source, note the lack of comments which made figuring out what the code was actually doing a big chore:</p><p><pre class="brush: cpp">string chatData;

message-&gt;getStringUnicode16(chatData);
chatData.convert(BSTRType_ANSI);

int8* data = chatData.getRawData();
uint16 len = chatData.getLength();

char chatElement[5][32];

uint8 element        = 0;
uint8 elementIndex    = 0;
uint16 byteCount    = 0;

while(element &lt; 5)
{
    if(*data == ' ')
    {
        chatElement[element][elementIndex] = 0;
        byteCount&#43;&#43;;
        element&#43;&#43;;
        data&#43;&#43;;
        elementIndex = 0;
        continue;
    }
    
    chatElement[element][elementIndex] = *data;
    elementIndex&#43;&#43;;
    byteCount&#43;&#43;;
    data&#43;&#43;;
}

// Convert the chat elements to logical types before passing them on.
uint64_t chat_target_id;
try    {
    chat_target_id    = boost::lexical_cast&lt;uint64&gt;(chatElement[0]);
} catch(boost::bad_lexical_cast &amp;) {
    chat_target_id    = 0;
}

SocialChatType chat_type_id = static_cast&lt;SocialChatType&gt;(atoi(chatElement[1]));
MoodType mood_id = static_cast&lt;MoodType&gt;(atoi(chatElement[2]));
    
string chatMessage(data);</pre></p><p>After careful examination you can see that the string is converted from utf16 to ansi format, then the string is looped over looking for the 5 integers (in string format) and finally placing the leftover data into a new string. Very complicated, brittle, and failes horribly in the case of strings that require utf16 format. Someone in the past also had decided it would be a good idea to typedef a custom BString class to string, which has been an endless source of confusion as well.</p><p>Here is my &quot;homework&quot; solution which makes use of several STL algorithms to achieve the desired results:</p><p><pre class="brush: cpp">// Get the unicode data and convert it to ansii, then get the raw data.
std::u16string chat_data = message-&gt;getStringUnicode16();

std::vector&lt;std::u16string&gt; tmp;
std::vector&lt;uint64_t&gt; chat_elements;
int elements_size = 0;

// The spatial chat data is all in a ustring. This consists of 5 chat elements
// and the text of the spatial chat. The 5 chat elements are integers that are
// sent as strings so here we use an istream_iterator which splits the strings
// at spaces.
std::basic_istringstream&lt;char16_t&gt; iss(chat_data);
std::copy_n(std::istream_iterator&lt;std::u16string, char16_t, std::char_traits&lt;char16_t&gt;&gt;(iss), 5,
    std::back_inserter&lt;std::vector&lt;std::u16string&gt;&gt;(tmp));

// Now we use the STL transform to convert the vector of std::u16string to a vector of uint64_t.
try {
    std::transform(tmp.begin(), tmp.end(), std::back_inserter&lt;std::vector&lt;uint64_t&gt;&gt;(chat_elements),
        [&amp;elements_size] (const std::u16string&amp; s) -&gt; uint64_t {
            // Convert the element to a uint64_t
            uint64_t output = boost::lexical_cast&lt;uint64_t&gt;(std::string(s.begin(), s.end())); 

            // After successful conversion update we need to store how long
            // the string was (plus 1 for the space delimiter that came after it).
            elements_size &#43;= s.size() &#43; 1; 

            return output;
        });
} catch(const boost::bad_lexical_cast&amp; e) {
    LOG(ERROR) &lt;&lt; e.what();
    return; // We suffered an unrecoverable error, bail out now.
}

// After pulling out the chat elements store the rest of the data as the spatial text body.
std::u16string spatial_text(chat_data.begin()&#43;elements_size, chat_data.end());</pre></p><p>The above works like a charm! My only complaint is the lack of string literal identifiers in vc2010 when working with std::u16string and std::u32string, however, it's not a dealbreaker (ie., I can't do something like:</p><p><pre class="brush: cpp">std::u16string mystring(u&quot;Some text goes here&quot;);</pre></p><p>).</p><p>Thanks again for a great series, you're definitely making an impact in the C&#43;&#43; community!</p><p>posted by devcodex</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-6-of-n#c634229623210000000</link>
		<pubDate>Mon, 18 Oct 2010 01:32:01 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-6-of-n#c634229623210000000</guid>
		<dc:creator>devcodex</dc:creator>
	</item>
</channel>
</rss>