Opened 10 years ago

Closed 4 years ago

#7659 closed Bugs (wontfix)

sizeof(tribool) > sizeof(bool) * 2

Reported by: anonymous Owned by: James E. King, III
Milestone: To Be Determined Component: logic
Version: Boost 1.52.0 Severity: Optimization
Keywords: Cc:

Description

I was wondering why tribool is 4 times larger than a simple bool (tested with msvc10 in 32bit and g++ 4.6.2 on 64bit). By looking at the sourcecode I am suspecting the internal enum always gets compiled as a 4byte int. When using the similar boost::optional<bool> I get at least as good as the naive implementation using two bools, but actually I was expecting a class tribool to be sizeof(bool) *and* encode the third value in the 7 unused bits of the single bool member field.

If this has been a design decision I think this is a decision that should be documented.

Change History (2)

comment:1 by James E. King, III, 4 years ago

Owner: changed from Douglas Gregor to James E. King, III

comment:2 by James E. King, III, 4 years ago

Resolution: wontfix
Status: newclosed

The class was created before C++11 scoped enums where it would have been possible to make this a single byte or even 2 bits. As such, given the age of this request and the length of time the class has been around, the need for backwards compatibility, and the relative disinterest in the ticket, I am closing this out.

Note: See TracTickets for help on using tickets.