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


Groups > comp.lang.c++ > #88416 > unrolled thread

Bitset with data type based upon value ranges

Started byAaron Gray <aaronngray@gmail.com>
First post2023-01-06 16:14 -0800
Last post2023-01-07 15:46 -0800
Articles 11 — 4 participants

Back to article view | Back to comp.lang.c++


Contents

  Bitset with data type based upon value ranges Aaron Gray <aaronngray@gmail.com> - 2023-01-06 16:14 -0800
    Re: Bitset with data type based upon value ranges Aaron Gray <aaronngray@gmail.com> - 2023-01-06 17:48 -0800
      Re: Bitset with data type based upon value ranges "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-01-07 12:45 -0800
        Re: Bitset with data type based upon value ranges Aaron Gray <aaronngray@gmail.com> - 2023-01-07 16:42 -0800
          Re: Bitset with data type based upon value ranges Muttley@dastardlyhq.com - 2023-01-09 09:18 +0000
    Re: Bitset with data type based upon value ranges Muttley@dastardlyhq.com - 2023-01-07 11:19 +0000
      Re: Bitset with data type based upon value ranges Aaron Gray <aaronngray@gmail.com> - 2023-01-07 09:32 -0800
    Re: Bitset with data type based upon value ranges Öö Tiib <ootiib@hot.ee> - 2023-01-07 08:49 -0800
      Re: Bitset with data type based upon value ranges Aaron Gray <aaronngray@gmail.com> - 2023-01-07 09:30 -0800
        Re: Bitset with data type based upon value ranges Öö Tiib <ootiib@hot.ee> - 2023-01-07 10:09 -0800
          Re: Bitset with data type based upon value ranges Aaron Gray <aaronngray@gmail.com> - 2023-01-07 15:46 -0800

#88416 — Bitset with data type based upon value ranges

FromAaron Gray <aaronngray@gmail.com>
Date2023-01-06 16:14 -0800
SubjectBitset with data type based upon value ranges
Message-ID<cbda91e9-0c7b-428e-a3fb-f930acc27627n@googlegroups.com>
Hi,
I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class.

0...7 - unsigned char
8..15 - unsigned short
16...31 - unsigned int
32...63 - unsigned long
64...127 - unsigned long long
128... - unsigned long long [] - array

```
#include <cstddef>

template <size_t BITS>
class bitset {
public:
    ....
    WORDTYPE data;
    ....
};
```

I am looking for solutions both with and without concepts for comparison, if its possible without and its simpler I will use that solution unless there is some real advantages to using concepts.

Many thanks in advance,

Aaron

[toc] | [next] | [standalone]


#88418

FromAaron Gray <aaronngray@gmail.com>
Date2023-01-06 17:48 -0800
Message-ID<8c2d02df-ff87-4fe2-ac76-d6103927d169n@googlegroups.com>
In reply to#88416
On Saturday, 7 January 2023 at 00:14:35 UTC, Aaron Gray wrote:
> Hi, 
> I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class. 
> 
> 0...7 - unsigned char 
> 8..15 - unsigned short 
> 16...31 - unsigned int 
> 32...63 - unsigned long 
> 64...127 - unsigned long long 
> 128... - unsigned long long [] - array 
> 
> ``` 
> #include <cstddef> 
> 
> template <size_t BITS> 
> class bitset { 
> public: 
> .... 
> WORDTYPE data; 
> .... 
> }; 
> ``` 

ChatGTP has given me the following :-
```
#include <type_traits>

template <size_t BITS>
class bitset {
public:
    static_assert(BITS > 0, "Number of bits must be positive");

    using WORDTYPE = typename std::conditional<BITS <= 8, unsigned char,
                     typename std::conditional<BITS <= 15, unsigned short,
                     typename std::conditional<BITS <= 31, unsigned int,
                     typename std::conditional<BITS <= 63, unsigned long,
                     typename std::conditional<BITS <= 127, unsigned long long,
                                               unsigned long long[]>::type>::type>::type>::type;

    WORDTYPE data;
    // ...
};
```

A good start, but withh two bugs, a missing extra '>::type' and the array really wants to be a whole new template specialization with WORDTYPE :-

    unsigned long long[(BITS+127)/128]

> I am looking for solutions both with and without concepts for comparison, if its possible without and its simpler I will use that solution unless there is some real advantages to using concepts. 

I am thinking concepts may be necessary ?

If you would like to help on the journey it would be well appreciated :)

Aaron

[toc] | [prev] | [next] | [standalone]


#88427

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-01-07 12:45 -0800
Message-ID<tpcllh$3jhcp$1@dont-email.me>
In reply to#88418
On 1/6/2023 5:48 PM, Aaron Gray wrote:
> On Saturday, 7 January 2023 at 00:14:35 UTC, Aaron Gray wrote:
>> Hi,
>> I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class.
>>
>> 0...7 - unsigned char
>> 8..15 - unsigned short
>> 16...31 - unsigned int
>> 32...63 - unsigned long
>> 64...127 - unsigned long long
>> 128... - unsigned long long [] - array
>>
>> ```
>> #include <cstddef>
>>
>> template <size_t BITS>
>> class bitset {
>> public:
>> ....
>> WORDTYPE data;
>> ....
>> };
>> ```
> 
> ChatGTP has given me the following :-
[...]

Ouch. ChatGTP seems to train itself when somebody has to correct its 
generated code that it likely lifted from somebody else. Also, is the 
correction correct itself?

[toc] | [prev] | [next] | [standalone]


#88432

FromAaron Gray <aaronngray@gmail.com>
Date2023-01-07 16:42 -0800
Message-ID<337270f4-10e8-428d-adb8-8d93d81d95dan@googlegroups.com>
In reply to#88427
On Saturday, 7 January 2023 at 20:45:54 UTC, Chris M. Thomasson wrote:
> On 1/6/2023 5:48 PM, Aaron Gray wrote: 
> > On Saturday, 7 January 2023 at 00:14:35 UTC, Aaron Gray wrote: 
> >> Hi, 
> >> I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class. 
> >> 
> >> 0...7 - unsigned char 
> >> 8..15 - unsigned short 
> >> 16...31 - unsigned int 
> >> 32...63 - unsigned long 
> >> 64...127 - unsigned long long 
> >> 128... - unsigned long long [] - array 
> >> 
> >> ``` 
> >> #include <cstddef> 
> >> 
> >> template <size_t BITS> 
> >> class bitset { 
> >> public: 
> >> .... 
> >> WORDTYPE data; 
> >> .... 
> >> }; 
> >> ``` 
> > 
> > ChatGTP has given me the following :-
> [...] 
> 
> Ouch. ChatGTP seems to train itself when somebody has to correct its 
> generated code that it likely lifted from somebody else. Also, is the 
> correction correct itself?

Yep, big ouch, it stung me, and wasted time. 

[toc] | [prev] | [next] | [standalone]


#88450

FromMuttley@dastardlyhq.com
Date2023-01-09 09:18 +0000
Message-ID<tpgm5o$1frk$1@gioia.aioe.org>
In reply to#88432
On Sat, 7 Jan 2023 16:42:14 -0800 (PST)
Aaron Gray <aaronngray@gmail.com> wrote:
>On Saturday, 7 January 2023 at 20:45:54 UTC, Chris M. Thomasson wrote:
>> On 1/6/2023 5:48 PM, Aaron Gray wrote: 
>> > On Saturday, 7 January 2023 at 00:14:35 UTC, Aaron Gray wrote: 
>> >> Hi, 
>> >> I am looking for some template code to generate a type based upon a
>constant within value ranges, for specialization of a bitset class. 
>> >> 
>> >> 0...7 - unsigned char 
>> >> 8..15 - unsigned short 
>> >> 16...31 - unsigned int 
>> >> 32...63 - unsigned long 
>> >> 64...127 - unsigned long long 
>> >> 128... - unsigned long long [] - array 
>> >> 
>> >> ``` 
>> >> #include <cstddef> 
>> >> 
>> >> template <size_t BITS> 
>> >> class bitset { 
>> >> public: 
>> >> .... 
>> >> WORDTYPE data; 
>> >> .... 
>> >> }; 
>> >> ``` 
>> > 
>> > ChatGTP has given me the following :-
>> [...] 
>> 
>> Ouch. ChatGTP seems to train itself when somebody has to correct its 
>> generated code that it likely lifted from somebody else. Also, is the 
>> correction correct itself?
>
>Yep, big ouch, it stung me, and wasted time. 

What did you expect? ANNs are at their core simply statistical algorithms. 
You'd probably get a similar result with a hidden markov model if it was given 
enough input though admittedly it couldn't parse your question.

[toc] | [prev] | [next] | [standalone]


#88420

FromMuttley@dastardlyhq.com
Date2023-01-07 11:19 +0000
Message-ID<tpbkfc$3rr$1@gioia.aioe.org>
In reply to#88416
On Fri, 6 Jan 2023 16:14:26 -0800 (PST)
Aaron Gray <aaronngray@gmail.com> wrote:
>Hi,
>I am looking for some template code to generate a type based upon a constant
>within value ranges, for specialization of a bitset class.
>
>0...7 - unsigned char
>8..15 - unsigned short
>16...31 - unsigned int
>32...63 - unsigned long
>64...127 - unsigned long long
>128... - unsigned long long [] - array
>
>```
>#include <cstddef>
>
>template <size_t BITS>
>class bitset {
>public:
>    ....
>    WORDTYPE data;
>    ....
>};
>```
>
>I am looking for solutions both with and without concepts for comparison, if
>its possible without and its simpler I will use that solution unless there is
>some real advantages to using concepts.
>
>Many thanks in advance,

Do you own coursework.

[toc] | [prev] | [next] | [standalone]


#88425

FromAaron Gray <aaronngray@gmail.com>
Date2023-01-07 09:32 -0800
Message-ID<d5b7ffe1-b786-4a7a-bf2d-1b065408d84bn@googlegroups.com>
In reply to#88420
On Saturday, 7 January 2023 at 11:19:27 UTC, Mut... wrote:
> On Fri, 6 Jan 2023 16:14:26 -0800 (PST) 
> Aaron Gray wrote: 
> >Hi, 
> >I am looking for some template code to generate a type based upon a constant 
> >within value ranges, for specialization of a bitset class. 
> > 
> >0...7 - unsigned char 
> >8..15 - unsigned short 
> >16...31 - unsigned int 
> >32...63 - unsigned long 
> >64...127 - unsigned long long 
> >128... - unsigned long long [] - array 
> > 
> >``` 
> >#include <cstddef> 
> > 
> >template <size_t BITS> 
> >class bitset { 
> >public: 
> > .... 
> > WORDTYPE data; 
> > .... 
> >}; 
> >``` 
> > 
> >I am looking for solutions both with and without concepts for comparison, if 
> >its possible without and its simpler I will use that solution unless there is 
> >some real advantages to using concepts. 
> > 
> >Many thanks in advance,
> Do you own coursework.

No I am an open source software engineer.

Aaron

[toc] | [prev] | [next] | [standalone]


#88423

FromÖö Tiib <ootiib@hot.ee>
Date2023-01-07 08:49 -0800
Message-ID<8b9f06f7-e750-4336-9baa-3b96e2ed35c4n@googlegroups.com>
In reply to#88416
On Saturday, 7 January 2023 at 02:14:35 UTC+2, aaron...@gmail.com wrote:
> Hi, 
> I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class. 
> 
But it is trivial with std::conditional in <type_traits>. Also the example
in <https://en.cppreference.com/w/cpp/types/conditional> is almost what
you asked for. So what is the problem? 

Otherwise you can freely get innumerable implementations of bitset. 
The std::bitset, QBitArray, boost::dynamic_bitset, std::vector<bool> are more popular.
So you should be swimming over your head lake of code ... not be asking for more
of it.  

[toc] | [prev] | [next] | [standalone]


#88424

FromAaron Gray <aaronngray@gmail.com>
Date2023-01-07 09:30 -0800
Message-ID<c5f4f7bf-d073-4ac9-9b9a-41f3c873d0f6n@googlegroups.com>
In reply to#88423
On Saturday, 7 January 2023 at 16:49:46 UTC, Öö Tiib wrote:
> On Saturday, 7 January 2023 at 02:14:35 UTC+2, Aaron Gray wrote: 
> > Hi, 
> > I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class. 
> >
> But it is trivial with std::conditional in <type_traits>. Also the example 
> in <https://en.cppreference.com/w/cpp/types/conditional> is almost what 
> you asked for. So what is the problem? 
> 
> Otherwise you can freely get innumerable implementations of bitset. 
> The std::bitset, QBitArray, boost::dynamic_bitset, std::vector<bool> are more popular. 
> So you should be swimming over your head lake of code ... not be asking for more 
> of it.

I am trying to put together a very efficient implementation to deal with fixed number of bits for dealing with lookahead sets for closure FIRST set guards for recursive decent parsers and a recursive descent parser generator. So want to use my own specific implmentation.

Aaron

[toc] | [prev] | [next] | [standalone]


#88426

FromÖö Tiib <ootiib@hot.ee>
Date2023-01-07 10:09 -0800
Message-ID<82f82e83-33d9-4843-95f0-1cdca66d93adn@googlegroups.com>
In reply to#88424
On Saturday, 7 January 2023 at 19:31:00 UTC+2, aaron...@gmail.com wrote:
> On Saturday, 7 January 2023 at 16:49:46 UTC, Öö Tiib wrote:
> > On Saturday, 7 January 2023 at 02:14:35 UTC+2, Aaron Gray wrote: 
> > > Hi, 
> > > I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class. 
> > > 
> > But it is trivial with std::conditional in <type_traits>. Also the example 
> > in <https://en.cppreference.com/w/cpp/types/conditional> is almost what 
> > you asked for. So what is the problem? 
> > 
> > Otherwise you can freely get innumerable implementations of bitset. 
> > The std::bitset, QBitArray, boost::dynamic_bitset, std::vector<bool> are more popular. 
> > So you should be swimming over your head lake of code ... not be asking for more 
> > of it.
> I am trying to put together a very efficient implementation to deal with fixed number of bits for dealing with lookahead sets for closure FIRST set guards for recursive decent parsers and a recursive descent parser generator. So want to use my own specific implmentation. 
> 
The std::conditional runs compile time so you can not get more efficient than
that.

[toc] | [prev] | [next] | [standalone]


#88431

FromAaron Gray <aaronngray@gmail.com>
Date2023-01-07 15:46 -0800
Message-ID<37f49c89-6cc2-4438-9322-82c4ca92bcban@googlegroups.com>
In reply to#88426
On Saturday, 7 January 2023 at 18:09:55 UTC, Öö Tiib wrote:
> On Saturday, 7 January 2023 at 19:31:00 UTC+2, aaron...@gmail.com wrote: 
> > On Saturday, 7 January 2023 at 16:49:46 UTC, Öö Tiib wrote: 
> > > On Saturday, 7 January 2023 at 02:14:35 UTC+2, Aaron Gray wrote: 
> > > > Hi, 
> > > > I am looking for some template code to generate a type based upon a constant within value ranges, for specialization of a bitset class. 
> > > > 
> > > But it is trivial with std::conditional in <type_traits>. Also the example 
> > > in <https://en.cppreference.com/w/cpp/types/conditional> is almost what 
> > > you asked for. So what is the problem? 
> > > 
> > > Otherwise you can freely get innumerable implementations of bitset. 
> > > The std::bitset, QBitArray, boost::dynamic_bitset, std::vector<bool> are more popular. 
> > > So you should be swimming over your head lake of code ... not be asking for more 
> > > of it. 
> > I am trying to put together a very efficient implementation to deal with fixed number of bits for dealing with lookahead sets for closure FIRST set guards for recursive decent parsers and a recursive descent parser generator. So want to use my own specific implmentation. 
> >
> The std::conditional runs compile time so you can not get more efficient than 
> that.

yep, its the types that matter :)

Aaron

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web