boost

Question on boost array initializer

I am trying to understand the boost array. The code can be read easily from author's site. In the design rationale, author (Nicolai M. Josuttis) mentioned that the following two types of initialization is possible. boost::array<int,4> a = { { 1, 2, 3 } }; // Line 1 boost::array<int,4> a = { 1, 2, 3 }; // Line 2 In my experimen...

How to accomplish covariant return types when returning a shared_ptr?

using namespace boost; class A {}; class B : public A {}; class X { virtual shared_ptr<A> foo(); }; class Y : public X { virtual shared_ptr<B> foo(); }; The return types aren't covariant (nor are they, therefore, legal), but they would be if I was using raw pointers instead. What's the commonly accepted idiom to work around thi...

How to prevent anyone from stealing my shared_ptr?

So, I use boost::shared_ptr for all the various reference-counting benefits it provides -- reference counting for starters, obviously, but also the ability to copy, assign, and therefore store in STL Containers. The problem is, if I pass it to just one "malicious" function or object, the object can save the ptr and then I'll never be ab...

Container for database-like searches

I'm looking for some STL, boost, or similar container to use the same way indexes are used in databases to search for record using a query like this: select * from table1 where field1 starting with 'X'; or select * from table1 where field1 like 'X%'; I thought about using std::map, but I cannot because I need to search for fields t...

Why does Visual Studio 2010 throw this error with Boost 1.42.0?

I'm trying to recompile application, that compiles fine with warning level 4 in visual studio 2005 and visual studio 2008. Since the errors (look below) are coming from std:tr1, I'm thinking there's some conflict, but not sure how to fix. My first thought was to remove all references to boost, such as but then I get an error that it can...

Matrix multiplication using Matrix Template library (MTL 4)

The program is as following: #include <iostream> #include <boost/numeric/mtl/mtl.hpp> using namespace mtl; int main(int argc, char* argv[]) { dense_vector<double> a(5,1.0); dense_vector<double> b(5,2.0); a * trans(b); } I want to calculate a * trans(b), but there is a compling error :C2893. Will someone help me? Thanks a lot! ...

Boost graph: Apply algorithms considering a specific edge subset.

Hi, I've got a huge graph with typed edge (i.e. edge with a type property). Say typedef adjacency_list<vecS, vecS, vertex_prop, edge_prop> Graph; The "type" of the edge is a member of edge_prop and has a value in {A,B,C,D}, I'd like to run the breadth first search algorithm considering only edges of type A or B. How would you do ...

Iterator failure while moving over equal_range in Boost MultiIndex container

I'm making some mistake with my iterators, but I can't see it yet. I have a Boost MultiIndex container, HostContainer hmap, whose elements are boost::shared_ptr to members of class Host. All the indices work on member functions of class Host. The third index is by Host::getHousehold(), where the household member variable is an int. Be...

bjam wih visual studio 2010

ok, so I ran into problems with Boost under visual studio 2010, so I decided to rebuild it with bjam: such as: bjam --toolset=msvc-10.0 --build-type=complete After running bjam (successfully?) it created a new directory under boost_1_42_0 called: bin.v2 Inside bin.v2 is directory called: libs. Two issues: 1. there's lot less libs unde...

(How) Can I approximate a "dynamic" index (key extractor) for Boost MultiIndex?

I have a MultiIndex container of boost::shared_ptrs to members of class Host. These members contain private arrays bool infections[NUM_SEROTYPES] revealing Hosts' infection statuses with respect to each of 1,...,NUM_SEROTYPES serotypes. I want to be able to determine at any time in the simulation the number of people infected with a give...

boost::interprocess::message_queue stops working in Release mode with visual C++

I am using boost::interprocess::message_queue, with VC++ (in Microsoft Visual Studio 2005). It is working properly in Debug mode. Then when I compile my program in Release mode it stops working, every time I call "try_send" it returns false. I don't understand what could be the settings that are different between Release and Debug mode, ...

How do I compile boost using __cdecl calling convention?

I have a project compiled using __cdecl calling convention (msvc2010) and I compiled boost using the same compiler using the default settings. The project linked with boost but I at runtime I got an assert message like this: File: ...\boost\boost\program_options\detail\parsers.hpp Line: 79 Run-Time Check Failure #0 - The value of ESP w...

Use boost library in cocoa project

It is theoretically possible to use a boost library (e.g. boost threads) inside a cocoa project? ...

Returning references while using shared_ptrs

Suppose I have a rather large class Matrix, and I've overloaded operator== to check for equality like so: bool operator==(Matrix &a, Matrix &b); Of course I'm passing the Matrix objects by reference because they are so large. Now i have a method Matrix::inverse() that returns a new Matrix object. Now I want to use the inverse directl...

Boost's "cstdint" Usage

Boost's C99 stdint implementation is awfully handy. One thing bugs me, though. They dump all of their typedefs into the boost namespace. This leaves me with three choices when using this facility: Use "using namespace boost" Use "using boost::[u]<type><width>_t" Explicitly refer to the target type with the boost:: prefix; e.g., boost::...

Boost installisation on windows

i have downloaded boost_1_42_0,zip but i'm not sure how to set it up. does http://www.boostpro.com/download/boost_1_42_setup.exe has to do something with it? ...

bitset to dynamic bitset

Hi.. I have a function where i use bitset.Now i need to convert it to a dynamic bitset.. but i don't know how. Can somebody help me ? set<string> generateCandidates(set<string> ck,unsigned int k){ set<string> nk ; for (set<string>::const_iterator p = ck.begin( );p != ck.end( ); ++p){ for (set<string>::const_iterator q = ck.begin(...

No-op deallocator for boost::shared_ptr

Is there a stock no-op deallocator in Boost to use with boost::shared_ptr for static objects, etc. I know it's ultra-trivial to write, but I don't want to sprinkle my code with extra tiny functions if there is already one available. ...

why is unbounded_array more efficient than vector?

It says here that The unbounded array is similar to a std::vector in that in can grow in size beyond any fixed bound. However unbounded_array is aimed at optimal performance. Therefore unbounded_array does not model a Sequence like std::vector does. What does this mean? ...

boost::python string-convertible properties

I have a C++ class, which has the following methods: class Bar { ... const Foo& getFoo() const; void setFoo(const Foo&); }; where class Foo is convertible to std::string (it has an implicit constructor from std::string and an std::string cast operator). I define a Boost.Python wrapper class, which, among other things, defines...