473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

boolean arrays

Hello there,

I need to store arrays as bit-vectors meaning that i.e. m entries are
stored in a single word on a machine with word size m. I am working on
C++ in unix environement. For any help I am very grateful!

Kind Regards,
amira

Feb 20 '06 #1
8 2302
Amira wrote:
Hello there,

I need to store arrays as bit-vectors meaning that i.e. m entries are
stored in a single word on a machine with word size m. I am working on
C++ in unix environement. For any help I am very grateful!


Take a look at:

std::vector<bool>
std::bitset<m>

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Feb 20 '06 #2
Ben Pope wrote:
Take a look at:

std::vector<bool>
std::bitset<m>


Neither of which is guaranteed to use a compact representation. The
interfaces of these two classes allow a compact representation,
however.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 20 '06 #3
Ben Pope wrote:
Amira wrote:
Hello there,

I need to store arrays as bit-vectors meaning that i.e. m entries are
stored in a single word on a machine with word size m. I am working on
C++ in unix environement. For any help I am very grateful!

Take a look at:

std::vector<bool>
std::bitset<m>

Ben Pope


Don't use std::vector<bool>, it is not an STL conforming container, and
afaik it is (soon to be) deprecated. Either use bitset, or
boost::dynamic_bitset.

--
Regards,

Ferdi Smit (M.Sc.)
Email: Fe********@cwi.nl
Room: C0.07 Phone: 4229
INS3 Visualization and 3D Interfaces
CWI Amsterdam, The Netherlands
Feb 20 '06 #4
Ferdi Smit wrote:
Don't use std::vector<bool>, it is not an STL conforming container,
Nor could any other container providing a compact representation
of Boolean be a conforming STL container: the element access, be
it by the index operator or the iterator dereference, is required
to provide a reference but there is no such thing as bit reference
in C++. Unless the STL requirements are changed (which is likely
although the details are not yet fixed), you cannot have both a
compact representation of Booleans and a conforming container.
However, if the requirements are changed, 'std::vector<bool>' will
likely become a suitable STL container.
and afaik it is (soon to be) deprecated.


There are some who dislike 'std::vector<bool>' and want it
deprecated. Since this does not solve the actual problem, i.e.
the inability to use sequences of r-values which are also important
in other situations than accessing bits, I doubt that
'std::vector<bool>' is going to be deprecated. I have, however, no
real idea on how the route towards having different versions of
library components will look like.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 20 '06 #5
Amira <pa********@gmail.com> wrote:
I need to store arrays as bit-vectors meaning that i.e. m entries are
stored in a single word on a machine with word size m. I am working on
C++ in unix environement. For any help I am very grateful!


As others have mentioned, you can try std::vector<bool> or
std::bitset<>. However, if these do not satisfy your requirements, then
you can use unsigned integral types and bitwise operators.

--
Marcus Kwok
Feb 20 '06 #6

Ferdi Smit wrote:
Ben Pope wrote:
Amira wrote:
Hello there,

I need to store arrays as bit-vectors meaning that i.e. m entries are
stored in a single word on a machine with word size m. I am working on
C++ in unix environement. For any help I am very grateful!

Take a look at:

std::vector<bool>
std::bitset<m>

Ben Pope


Don't use std::vector<bool>, it is not an STL conforming container


The topic starter is looking for a container which due to the
requirements
cannot be an STL conforming container. Any other alternative suggested
will have exactly the same "problem" or fail to meet the stated
requirements.

HTH,
Michiel Salters

Feb 20 '06 #7
Mi*************@tomtom.com wrote:
The topic starter is looking for a container which due to the
requirements
cannot be an STL conforming container. Any other alternative suggested
will have exactly the same "problem" or fail to meet the stated
requirements.


Any alternative container will not claim to be an STL container, nor
look like one. Nobody will be tempted to use it's iterators (if they
even exist) as input to algorithms. (and we've discussed this before :) )
--
Regards,

Ferdi Smit (M.Sc.)
Email: Fe********@cwi.nl
Room: C0.07 Phone: 4229
INS3 Visualization and 3D Interfaces
CWI Amsterdam, The Netherlands
Feb 20 '06 #8

Ferdi Smit wrote:
Mi*************@tomtom.com wrote:
> The topic starter is looking for a container which due to the
requirements
cannot be an STL conforming container. Any other alternative suggested
will have exactly the same "problem" or fail to meet the stated
requirements.


Any alternative container will not claim to be an STL container, nor
look like one. Nobody will be tempted to use it's iterators (if they
even exist) as input to algorithms. (and we've discussed this before :) )


Actually, you can use vector<bool> iterators as input to STL
algorithms.

HTH,
Michiel Salters

Feb 21 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators...
16
by: Ian Tuomi | last post by:
How can I define a boolean value in c? (an value that can only be either 1 or 0) I feel bad for the memory loss when declaring ints for variables that do not need that much memory. -- Ian Tuomi...
17
by: jacob navia | last post by:
The section about boolean values should mention <stdbool.h> at least. It is still at the C89 stage... (Section 9)
3
by: Trent Buck | last post by:
(Note: C99 supports variadic macros, but C89 does not.) I'm pretty sure what I'm trying to do is impossible, but I'll ask here in case I'm missing something. I'm trying to define generic,...
11
by: Jason Heyes | last post by:
What STL algorithm do I use to set all bool elements of an array to false in just one line of code? Thanks!
0
by: andrewfelch | last post by:
Below is the code to/from Boolean arrays and Unsigned integers. On my Pentium 4, functions such as "bitwise_and" are 32 times faster when run on 32-bit integers instead of the...
76
by: KimmoA | last post by:
First of all: I love C and think that it's beautiful. However, there is at least one MAJOR flaw: the lack of a boolean type. OK. Some of you might refer to C99 and its _Bool (what's up with the...
14
by: Martin Wells | last post by:
I come from C++, and there's a type called "bool" in C++. It works exactly like any other integer type except that when promoted, it either becomes a one or a zero, so you can you bitwise operators...
3
by: Brian Smither | last post by:
$result = $class->method(); //returns an array of associative arrays if($result==TRUE) $cat=$result; I've been converting a class from an original and the original class *apparently* returned an...
270
by: Jordan | last post by:
Hi everyone, I'm a big Python fan who used to be involved semi regularly in comp.lang.python (lots of lurking, occasional posting) but kind of trailed off a bit. I just wrote a frustration...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.