boost

Store 2D points for quick retrieval of those inside a rectangle

I have a large number of 2D points and I want to quickly get those that lie in a certain rectangle. Let's say a '.' is any point and 'X' is a point I want to find inside a rectangle which has 'T' as TopLeft and 'B' as BottomRight points: . . . . . . . T-----+ . . | X X | . . +-----B . . . . . . . I have tried a std::set with a sort fu...

Why shared_ptr has an explicit constructor

I was wondering why shared_ptr doesn't have an implicit constructor. The fact it doesn't is alluded to here: http://stackoverflow.com/questions/142391/getting-a-boostsharedptr-for-this (I figured out the reason but thought it would be a fun question to post anyway.) #include <boost/shared_ptr.hpp> #include <iostream> using namespace b...

Boost Spirit crash when used in DLLs

I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my application. This only happens if I have used the Spirit parser during the lifetime of the process from the main thread. The crash happens at exit and appears to be related to the clean-up of thread specific storage allocated by the Spirit parser....

Passing boost::any to results of boost::bind

I'm trying to figure out how to write this function: template <typename Bound> Bound::result_type callFromAnyList(Bound b, list<any> p) { } Then, if I had some function: double myFunc(string s, int i) { return -3.0; } I could call it by doing something like this: list<any> p; p.push_back((string)"Hello"); p.push_back(7); doubl...

C++ Smart Pointer performance

How much do using smart pointers, particularly boost::shared_ptr cost more compared to bare pointers in terms of time and memory? Is using bare pointers better for performance intensive parts of gaming/embedded systems? Would you recommend using bare pointers or smart pointers for performance intensive components? ...

Can I use boost on uclibc linux?

Does anyone have any experience with running C++ applications that use the boost libraries on uclibc-based systems? Is it even possible? Which C++ standard library would you use? Is uclibc++ usable with boost? ...

std::auto_ptr or boost::shared_ptr for pImpl idiom?

When using the pImpl idiom is it preferable to use a boost:shared_ptr instead of a std::auto_ptr? I'm sure I once read that the boost version is more exception friendly? class Foo { public: Foo(); private: struct impl; std::auto_ptr<impl> impl_; }; class Foo { public: Foo(); private: struct impl; boost::shared_...

boost lambda for_each / transform puzzle

Does anybody know why vector<int> test(10); int a=0; for_each(test.begin(),test.end(),(_1+=var(a),++var(a))); for_each(test.begin(),test.end(),(cout << _1 << " ")); cout << "\n" Gives : "0 1 2 3 4 5 6 7 8 9" but transform(test.begin(),test.end(),test.begin(), (_1+=var(a),++var(a))); ...(as before) Gives : "1 2 3 ...

Why override operator() ?

In the Boost Signals library, they are overloading the () operator. Is this a convention in C++? For callbacks, etc.? I have seen this in code of a co-worker (who happens to be a big Boost fan). Of all the Boost goodness out there, this has only led to confusion for me. Any insight as to the reason for this overload? ...

boost::any_cast - throw only when an implicit conversion isn't available?

I want boost::any_cast<T> to only throw an exception when the type of the any doesn't have an implicit conversion to T. The normal behaviour seems to be to throw an exception if the type of the any is not T, regardless of implicit conversions. Example: boost::any a = 1; boost::any_cast<int>(a); // This succeeds, and rightfully so boost...

C++ Serialization Performance

Hi! I'm building a distributed C++ application that needs to do lots of serialization and deserialization of simple data structures that's being passed between different processes and computers. I'm not interested in serializing complex class hierarchies, but more of sending structures with a few simple members such as number, strings ...

Most used parts of Boost

When I discovered boost lexical_cast I thought to myself "why didn't I know about this sooner!" - I hated having to write code like stringstream ss; ss << anIntVal; mystring = ss.str(); Now I write mystring = boost::lexical_cast<string>(anIntVal); Yesterday, on stackoverflow, I came across boost split (another gem that will save ...

C++ - passing references to boost::shared_ptr

If I have a function that needs to work with a shared_ptr, wouldn't it be more efficient to pass it a reference to it (so to avoid copying the shared_ptr object)? What are the possible bad side effects? I envision two possible cases: 1) inside the function a copy is made of the argument, like in ClassA::take_copy_of_sp(boost::shared_pt...

Convert wide character strings to boost dates

I need to convert several million dates stored as wide strings into boost dates The following code works. However, it generates a horrible compiler warning and does not seem efficient. Is there a better way? #include "boost/date_time/gregorian/gregorian.hpp" using namespace boost::gregorian; #include <string> using namespace std; ...

Using boost::shared_ptr in a library's public interface

We have a C++ library that we provide to several different clients. Recently we made the switch from using raw pointers in the public interface to using boost::sharedptr instead. This has provided an enormous benefit, as you might guess, in that now the clients no longer have to worry about who needs to delete what and when. When we made...

Matrix Template Library matrix inversion

I'm trying to inverse a matrix with version Boost boost_1_37_0 and MTL mtl4-alpha-1-r6418. I can't seem to locate the matrix inversion code. I've googled for examples and they seem to reference lu.h that seems to be missing in the above release(s). Any hints? @Matt suggested copying lu.h, but that seems to be from MTL2 rather than MTL4....

shared_ptr: what's it used for

Hi all, I make a lot of use of boost::scoped_ptr in my code and it is great but I'm currently working with software that uses shared_ptr all over the place and I'm wondering if I'm missing something. AFAIK a shared_ptr is only useful if different threads are going to be accessing the same data and you don't know what order the threads...

Is there a "nice" way to deal with reassembling multicasts from multiple sources?

Hi all I'm currently reworking our existing proprietary socket wrapper code to use boost asio so that it can do some of the heavy lifting for us. Perhaps the most complex area of our existing code is the multicast handling code. The code allows our middle-tier servers (of which there can me many in one system) to send multicasts to c...

Multiple Integer-type classes in C++

I often find myself using Integers to represent values in different "spaces". For example... int arrayIndex; int usersAge; int daysToChristmas; Ideally, I'd like to have separate classes for each of these types "Index","Years" and "Days", which should prevent me accidentally mixing them up. Typedefs are a help from a documnentation pe...

How to detect deadlock whith Asio library?

Hi, i have little problem with boost::asio library. My app receive and process data asynchronously, it create threads and run io_service.run() on each of them. boost::asio::io_service io; boost::thread_group thread_pool; ... int cpu_cnt = get_cpu_count(); for (int i = 0; i < cpu_cnt; ++i) { thread_pool.create_thread( boost::bind(&ru...