boost

How can I return a const ref a to local variable in C++?

I have a function for which I cannot change the function parameters. I need to return a const reference to a std::string created in this function. I tried to use boost shared_ptr, but this doesn't work. Why? How do I make this work? const std::string& getVal(const std::string &key) { boost::shared_ptr<std::string> retVal(new std::...

Easiest way to repeat a sequence of bytes into a larger buffer in C++

Given (in C++) char * byte_sequence; size_t byte_sequence_length; char * buffer; size_t N; Assuming byte_sequence and byte_sequence_length are initialized to some arbitrary length sequence of bytes (and its length), and buffer is initialized to point to N * byte_sequence_length bytes, what would be the easiest way to replicate the byt...

Map of boost function of different types?

Hi, i was wondering if there was a way to do this in C++? void func1(const std::string& s) { std::cout << s << std::endl; } void func2(int me) { std::cout << me << std::endl; } int main() { std::map<std::string, boost::function< ??? > > a_map; a_map["func1"] = &func1; a_map["func1"]("HELLO"); } Is there any way to do what i have a...

Serialize and send a data structure using Boost?

I have a data structure that looks like this: typedef struct { unsigned short m_short1; unsigned short m_short2; unsigned char m_character; } MyDataType; I want to use boost::serialization to serialize this data structure, then use boost::asio to transmit it via TCP/IP, then have another application receive the data and de-seri...

Jamfile required ...

Can anyone help me ? I'm trying to add the testing facilities from boost library and I'm stuck. Let's suppose that i have a source file like this (the simplest one): #define BOOST_TEST_MAIN #include BOOST_AUTO_TEST_CASE(test) { BOOST_CHECK(1 + 1 == 2); } How is suppose to look the corespondent Jamfile ? Thank you ! ...

Passing a smart pointer as argument inside a class: scoped_ptr or shared_ptr ?

I have a class that creates an object inside one public method. The object is private and not visible to the users of the class. This method then calls other private methods inside the same class and pass the created object as a parameter: class Foo { ... }; class A { private: typedef scoped_ptr<Foo> FooPtr; void pri...

How to enable_shared_from_this of both parend and derived

Hello, I have simple base and derived class that I want both have shared_from_this(). This simple solution: class foo : public enable_shared_from_this<foo> { void foo_do_it() { cout<<"foo::do_it\n"; } public: virtual function<void()> get_callback() { return boost::bind(&foo::foo_do_it,shared_from_this()); } virtual ~foo() {}...

static members and boost serialization

I'm using Boost.Serialization to archive the contents of a class. One of the member variables is a static std::vector. Archiving and restoring goes fine, but I was kind of hoping the library would save static members only once, it appears that, judging by the filesize, the static members are fully saved for each archived instance. This...

C++: Cross thread exception handling problem with boost::exception

Basically, I've got a situation where one thread throws an exception which a different thread needs to handle. I'm trying to do this with boost exception, however somewhere along the line the exception loses its type and thus isn't caught by the catch blocks. Basically, thread B wants to do something, however for various reasons it mus...

Boost (BGL): How do dis-obfuscate my errors?

I seem to recall reading about a way to 'reduce' the size of template spew in compiler errors associated with the boost libraries. My recollection is that it gives the template parameters nicer names than the compiler default naming (which is quite horrid). Is this real, or did I dream about it? I've been trying to find where I read thi...

Best way to avoid a thousand if statements?

Hi I basically have this problem: right now, we have a system where it gets a string as input, and it basically says ACTION:. For each of the actions there is an automatically generated function(Rational Rose GRRR), such as bouncer_comm.chatMessage("data goes here").sendAt(msg->sapIndex0()); bouncer_comm.askforname().sendAt(msg->sapi...

Modifying vertex properties in a Boost::Graph

I am trying to figure out how to use boost::graph to store some information. However, there is information I want tied to each vertex. Staring at the documentation for the library reveals either(a)badly written documentation, or (b), I'm obviously not as good at C++ as I thought. Pick two. I am looking for either a tutorial on assigning...

boost::asio::ip::tcp::resolver::resolve() blocks forever...

I'm trying to create something similar as this code found at the boost.asio examples. socket.h: class some_class { private: ... boost::asio::io_service io_service; public: some_class() { /* This stuff isn't used in the example... ...but it doesn't change anything... */ io_ser...

C++ Serialization Performance

Hi, I'm building a distributed C++ application that needs to do lots of serialization and deserialization of data stored in std containers. Currently Boost.serialization is adopted. However, it performs terrible. Our B-tree also use Boost.serialization to store key-value pair data, however, if we change Boost.serialziation to memcpy, th...

How to detect whether an OS X application is already launched

Normally an application bundle on OS X can only be started once, however by simply copying the bundle the same application can be launched twice. What's the best strategy to detect and stop this possibility? On Windows this effect can simply be achieved by the application creating a named resource at launch and then exit if the named r...

Can multiple versions of a same (Boost) DLL co-exist in same process?

My (C++, cross-platform) app is heavily using Boost libraries (say version 1.x), and I want to also link against a 3rd-party (vendor)'s SDK (no source), itself using Boost (but version 1.y). So, we both link dynamically against our own version of Boost DLLs, CRT being identical. Consequently, at run-time my app would have to load both D...

Is boost shared_ptr <XXX> thread safe?

I have a question about boost :: shared_ptr. There are lots of thread. class CResource { xxxxxx } class CResourceBase { public: void SetResource(shared_ptr<CResource> res) { m_Res = res; } shared_ptr<CResource> GetResource() { return m_Res; } private: shared_ptr<CResource> m_Res; } CResourceBase base; ...

how do i get started using boost

I hear a lot about boost here and I am beginning to think it could help a lot with my software development. More so in concurrency and memory management in my particular case as we have had a lot of bugs in this area. What are the key language features I need to polish up on to effectively benefit from using boost and to shorten the le...

Specify the minimum number of buckets when constructing a boost::unordered_map

I am trying to use boost::unordered_map to cache some values. I try to specify minimum number of buckets in the constructor: #include <boost/unordered_map.hpp> typedef boost::unordered_map<float, float> Mycache; Mycache cache((std::size_t)25165843, boost::hash<float>(), std::equal_to<float>(), s...

boost serialization NVP macro and non-XML-element characters

When using the BOOST_SERIALIZATION_NVP macro to create a name-value pair for XML serialization, the compiler happily allows the following code to compile, even though the element name is not a valid XML element and an exceptions is thrown when trying to actually serialize the object into XML: BOOST_SERIALIZATION_NVP(_member[index]) An...