Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #41138

Re: String integer id

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c++
Subject Re: String integer id
Date Mon, 22 Feb 2016 23:02:19 +0000
Organization A noiseless patient Spider
Lines 46
Message-ID <874md0uz5w.fsf@bsb.me.uk> (permalink)
References <224a55e1-bcba-4063-915d-02f0b53dd294@googlegroups.com> <nafctc$sg0$1@dont-email.me> <623b57e7-5049-45a6-8887-0723228d8355@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="27204"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/Z7wE3cTcKoHZyD1lWgOwgjL41Iyvg4o="
Cancel-Lock sha1:Obt20qXKAgF96EnTTdRZRdPC8aY= sha1:zXlmKTFPjEfEwh7/vkGu9XWMvos=
X-BSB-Auth 1.158efdbd701801395385.20160222230219GMT.874md0uz5w.fsf@bsb.me.uk
Xref csiph.com comp.lang.c++:41138

Show key headers only | View raw


malcolm.mclean5@btinternet.com writes:

> On Monday, February 22, 2016 at 4:30:45 PM UTC, Alf P. Steinbach wrote:
>> On 22.02.2016 15:59, malcolm.mclean5@btinternet.com wrote:
>>
>> Is this a correct understanding?
>> 
>> * Each 64-bit id is usually chosen by the programmer.
>> 
>> * There is a (unspecified) two-way mapping between 64-bit id and 
>> 7-character human readable string.
>> 
>> * You're asking how to compute the unspecified mapping at compile time.
>> 
> The idea is that the id is an unsigned 64 bit integer, which is also
> an asciiz string
> of seven characters plus null.
> So if the id is "charlie" then the id is 99 (ascii c) * 2**56 + 104 *
> 2**48 and so on.
> So if there's some question about the ids, you can analyse the binary or 
> print the value out as a string, and you've got a human-meaningul enumeration
> value, e.g. "charlie", "andy", "anne" and "eddie" rather than 1, 2, 3,
> 4.

By "print the value as a string", I suspect you mean simply treating a
pointer to the integer as a character pointer.  If you want to do that,
you run into trouble with endianness if you build the value
arithmetically (as your example suggest).  For little-endian machines
you need the bytes to be packed with the other significance:

template <typename T>
static constexpr T make_id(const char *lit, std::size_t len, T r)
{
   return len ? make_id(lit, len - 1, (r << 8) + lit[len-1]) : r;
}

constexpr unsigned long long operator "" _id(const char *lit, std::size_t len)
{
   return make_id(lit, len >= sizeof 0ULL ? sizeof 0ULL - 1 : len, 0ULL);
}

I have not been able to come up with a constexpr method that puts the
bytes into an integer in address order.

-- 
Ben.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

String integer id malcolm.mclean5@btinternet.com - 2016-02-22 06:59 -0800
  Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-22 17:30 +0100
    Re: String integer id malcolm.mclean5@btinternet.com - 2016-02-22 09:04 -0800
      Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-22 19:03 +0100
        Re: String integer id malcolm.mclean5@btinternet.com - 2016-02-22 13:22 -0800
      Re: String integer id Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-22 23:02 +0000
        Re: String integer id Öö Tiib <ootiib@hot.ee> - 2016-02-22 15:16 -0800
          Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 19:54 -0500
            Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 02:26 +0100
              Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 20:35 -0500
                Re: String integer id legalize+jeeves@mail.xmission.com (Richard) - 2016-02-23 02:31 +0000
                Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 21:42 -0500
                Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 04:59 +0100
                Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-23 08:32 -0500
                Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 03:34 +0100
                Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 21:38 -0500
                Re: String integer id Google <google@google.com> - 2016-02-22 19:36 -0800
                Re: String integer id David Brown <david.brown@hesbynett.no> - 2016-02-23 09:25 +0100
                Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-23 08:33 -0500
                Re: String integer id David Brown <david.brown@hesbynett.no> - 2016-02-23 15:43 +0100
                Re: String integer id Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-23 11:21 -0500
                Re: String integer id woodbrian77@gmail.com - 2016-02-22 20:48 -0800
                Re: String integer id David Brown <david.brown@hesbynett.no> - 2016-02-23 09:16 +0100
                Re: String integer id Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-23 18:23 +0200
                Re: String integer id David Brown <david.brown@hesbynett.no> - 2016-02-23 22:29 +0100
  Re: String integer id Barry Schwarz <schwarzb@dqel.com> - 2016-02-22 11:41 -0800
    Re: String integer id Ian Collins <ian-news@hotmail.com> - 2016-02-23 09:13 +1300
      Re: String integer id Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-23 00:32 +0200
        Re: String integer id legalize+jeeves@mail.xmission.com (Richard) - 2016-02-22 22:39 +0000
          Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 00:46 +0100
          Re: String integer id Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-23 10:01 +0200
            Re: String integer id "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 19:15 +0100
              Re: String integer id Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-23 21:40 +0200
  Re: String integer id Juha Nieminen <nospam@thanks.invalid> - 2016-02-23 09:18 +0000
    Re: String integer id malcolm.mclean5@btinternet.com - 2016-02-23 03:15 -0800

csiph-web