220 6868 <ab789d12-9da0-4d7c-a456-23481262484d@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: fmatthew5876@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Comments on n3783: Network byte order
Date: Tue, 1 Oct 2013 20:56:10 -0700 (PDT)
Lines: 81
Approved: news@gmane.org
Message-ID: <ab789d12-9da0-4d7c-a456-23481262484d@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_4644_20755413.1380686170291"
X-Trace: ger.gmane.org 1380686168 23265 80.91.229.3 (2 Oct 2013 03:56:08 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 2 Oct 2013 03:56:08 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDELF54RTIGRBWVSV2JAKGQEJYRKM3Y@isocpp.org Wed Oct 02 05:56:13 2013
Return-path: <std-proposals+bncBDELF54RTIGRBWVSV2JAKGQEJYRKM3Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vb0-f69.google.com ([209.85.212.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDELF54RTIGRBWVSV2JAKGQEJYRKM3Y@isocpp.org>)
	id 1VRDXo-0004t1-BA
	for gclcip-std-proposals@m.gmane.org; Wed, 02 Oct 2013 05:56:12 +0200
Original-Received: by mail-vb0-f69.google.com with SMTP id e13sf561149vbg.4
        for <gclcip-std-proposals@m.gmane.org>; Tue, 01 Oct 2013 20:56:11 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe:content-type;
        bh=kElF9C8qC9AXBe+4s8Ii1ErAeqcuWT85df1rmzwhcE4=;
        b=xXHZLB4oHnNV7tc8NaP61TEjUksFquVoNUedCnVvaDjQ3E7j3nklifCPg2824V42nC
         zViDMKM5454EFFzmh+BjUEjTKds04UaV4Aay+Gc3tvDIJq+Xyt5riOHT+3COrba0ytam
         oTIXQKGXLhUgcvgR5sLpi3cGMaxH5yy9kGQXH/05GU3/RM3NXxwp8UuIpCMXrsezRze7
         afKngcGvO0gAk0cftI00W8e8IJeVu4aBdPxRcOKAcjAVquvsMmro6D/SMAti3TKmI27r
         9y7J3ORuxSOYrMZ0vbSapMXyymfSue6jqElQ3qiYz2ZUWGLwghzUY0hlzWZU4NpYBgLl
         tmZA==
X-Received: by 10.236.93.45 with SMTP id k33mr148004yhf.19.1380686171195;
        Tue, 01 Oct 2013 20:56:11 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.64.38 with SMTP id l6ls339011qes.89.gmail; Tue, 01 Oct 2013
 20:56:10 -0700 (PDT)
X-Received: by 10.49.72.65 with SMTP id b1mr2099qev.21.1380686170713;
        Tue, 01 Oct 2013 20:56:10 -0700 (PDT)
X-Original-Sender: fmatthew5876@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:6868
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/6868>

------=_Part_4644_20755413.1380686170291
Content-Type: text/plain; charset=ISO-8859-1

This proposal should be generalized to a more generic byte swapping 
solution. Something like:

//<bswap>
//Endianness
struct byte_order {
  enum order {
     little_endian,
     big_endian,
  };
order value = /*implementation defined*/;
};

//Cross-platform Byteswapping
template <typename T> constexpr T bswap(T val);
template <typename T> constexpr T cpu_to_be(T val) {
  return byte_order::value == little_endian ? bswap(val) : val;
}
template <typename T> constexpr T cpu_to_le(T val) {
  return byte_order::value == little_endian ? val : bswap(val);
}

//<net>

#include <bswap>
//Network byte order layer built ontop of bswap
template <typename T> constexpr T hton(T val) { return cpu_to_be(val); }

This is so easy and trivial to implement. Most compilers even have builtins 
for all of the byte swapping routines. I don't know why its not 
standardized.

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_4644_20755413.1380686170291
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>This proposal should be generalized to a more generic=
 byte swapping solution. Something like:</div><div><br></div><div>//&lt;bsw=
ap&gt;</div><div>//Endianness</div><div><div>struct byte_order {</div><div>=
&nbsp; enum order {</div><div>&nbsp; &nbsp; &nbsp;little_endian,</div><div>=
&nbsp; &nbsp; &nbsp;big_endian,<br>&nbsp; };</div><div>order value =3D /*im=
plementation defined*/;</div><div>};</div></div><div><br></div><div>//Cross=
-platform Byteswapping</div><div>template &lt;typename T&gt; constexpr T bs=
wap(T val);</div><div>template &lt;typename T&gt; constexpr T cpu_to_be(T v=
al) {</div><div>&nbsp; return byte_order::value =3D=3D little_endian ? bswa=
p(val) : val;<br>}</div><div>template &lt;typename T&gt; constexpr T cpu_to=
_le(T val) {</div><div>&nbsp; return byte_order::value =3D=3D little_endian=
 ? val : bswap(val);<br>}</div><div><br></div><div>//&lt;net&gt;</div><div>=
<br></div><div>#include &lt;bswap&gt;</div><div>//Network byte order layer =
built ontop of bswap</div><div>template &lt;typename T&gt; constexpr T hton=
(T val) { return cpu_to_be(val); }</div><div><br></div><div>This is so easy=
 and trivial to implement. Most compilers even have builtins for all of the=
 byte swapping routines. I don't know why its not standardized.</div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_4644_20755413.1380686170291--

.
