![]() |
| | #1 |
| Ex scientia vera Join Date: Sep 2007
Posts: 460
| std::bitset - Why on earth isn't it dynamically allocated? Do you guys have any idea why they chose to implement it as such? I am by no means an experiences C++ programmer, and I knew that it was possible to use templates to pass arguments like that, but am I the only one who thinks it's a perversion of the whole concept of generic programming? For some reason, I don't think it makes sense to be able to pass templates anything but types. I know boost has a bitset that does it dynamically, but I'm still curious as to the logic behind this design. It really limits its usage.
__________________ "What's up, Doc?" "'Up' is a relative concept. It has no intrinsic value." |
| IceDane is offline | |
| | #2 | |
| The larch Join Date: May 2006
Posts: 3,175
| It is much more efficient this way? You could similarly bash std::tr1::array for not allocating the array dynamically. It's not supposed to. If that is not what you need, use something else, like boost's dynamic_bitset. Besides, non-type template arguments are used heavily in C++ (e.g think boost and type_traits, half of which are instantiations of integer_constant<bool, true/false> or something like that. Neither should it particularly interfere with generic programming: Code: template <class Bitset> void foo(const Bitset& bs); //accepts all bitsets and anything else with a similar interface template <unsigned N> void foo(const std::bitset<N>& bs); //accepts bitsets of any size
__________________ I might be wrong. Quote:
Last edited by anon; 11-30-2009 at 04:48 AM. | |
| anon is offline | |
| | #3 | |
| Ex scientia vera Join Date: Sep 2007
Posts: 460
| Quote:
I did mention that boost has a dynamic bitset, but I still don't understand why the functionality wasn't provided from the get-go.
__________________ "What's up, Doc?" "'Up' is a relative concept. It has no intrinsic value." | |
| IceDane is offline | |
| | #4 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,923
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #5 | |
| The larch Join Date: May 2006
Posts: 3,175
| Dynamic allocations may be very expensive in C++. (If you see a benchmark where OMG Java is much faster than C++, the culprit seems to be quite often that the benchmark in reality tests the speed of small object allocation-deallocation.) Besides, there is a dynamic bitset in standard C++, and that's the vector<bool> specialization (it is deprecated, though, since it doesn't work like a container).
__________________ I might be wrong. Quote:
| |
| anon is offline | |
| | #6 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,664
| What would distinguish it from std::vector<bool> then?
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Structures and dynamically allocated arrays | Bandizzle | C Programming | 7 | 10-04-2009 02:05 PM |
| Dynamically allocated array | dre | C Programming | 17 | 08-13-2009 06:57 PM |
| dynamically allocated strings?? | CS_Student8337 | C Programming | 18 | 03-19-2009 05:14 AM |
| scope of dynamically allocated variables | lanzyzhang | C Programming | 4 | 07-20-2004 10:59 AM |