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::...
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...
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...
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...
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 !
...
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...
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() {}...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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;
...
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...
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...
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...