Questions tagged [boost-any]

Boost.Any is a C++ library that offers a safe, generic container for single values of different value types.

Boost.Any is a C++ library that offers a safe, generic container for single values of different value types.

118 questions
1
vote
3 answers

Boost: Vector of Distributions with any

Dear Stack Exchange Experts, I am trying to set up a class (multivariate distribution function) that stores boost distributions in a std::vector (marginal distribution functions). While this is possible using boost::variant (see my question: Boost:…
user3456032
  • 187
  • 1
  • 5
1
vote
1 answer

boost spirit, boost any and quoted string - compile-time error

I have the following code: #include #include #include #include template struct parser : boost::spirit::qi::grammar
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
1
vote
1 answer

boost spirit and boost any - unexpected result

I have the following code: #include #include #include #include template struct parser : boost::spirit::qi::grammar
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
1
vote
2 answers

boost::any replacement for the code below

I wish get rid of boost dependency on my code. I have the following struct construct. When calling and using this struct at another place in the code boost::any_cast is used. I know a template class would do it, but finding it hard to write this…
1
vote
2 answers

How can I return different type according to the value of parameter in C++?

I want to do something overload with different value of parameter in C++. Something like dynamic language such as Python: def foo(str): if str == "a": return str if str == "b": return true if str == "c": return 1 Is there some…
xunzhang
  • 2,838
  • 6
  • 27
  • 44
1
vote
1 answer

Is boost::any movable?

This code compiles but I don't think it does what I intended, that is, move, don't copy, the boost::any object that was created on the stack into a std::vector boost::any var; var = std::string("StackOverflow"); std::vector
user841550
  • 1,067
  • 3
  • 16
  • 25
1
vote
1 answer

Implementing an any container

I'm well aware of boost::any and boost::variant, but in this instance they don't fit my needs. Normally, to contain an object of unknown type, one would derive it from a common base and access the instance through virtual methods. But, what can one…
Twifty
  • 3,267
  • 1
  • 29
  • 54
1
vote
0 answers

boost any cast trouble when reading a plist file

I'm reading some data from a plist file in visual c++. data in file is somethig like this: Caminando_001.png x y width height offsetX offsetY originalWidth originalHeight I read until x key value and then I do something like int Left =…
Fabricio
  • 11
  • 1
1
vote
2 answers

Does boost::any save a copy or reference/pointer?

Is the following code safe? boost::any any_value; { std::string s = "HelloWorld"; any_value = s; } std::string ss = any_cast(any_value);
balki
  • 26,394
  • 30
  • 105
  • 151
0
votes
1 answer

C# - Any thing similar to boost::any?

I have a requirement where: 1. I need to store objects of any type in list 2. Avoid casting calls as much as possible To that end I tried to come up with something. No matter what I tried I could not get rid of boxing\unboxing. I wanted to know…
neel roy
  • 147
  • 1
  • 13
0
votes
1 answer

How to retrieve data from a std::list containing boost::shared_ptr

I need helping trying to retrieve data held in a std::list> I working on a Singleton Controller class with a private std::list. Client class(es) will be able to add/remove/edit concrete class objects to be used by the…
badboy11
  • 541
  • 1
  • 6
  • 19
0
votes
2 answers

boost::any destructor crash

Main exe loads dll. Calls function from dll returning simple boost::any. If boost::any deleted after FreeLibrary app crash at destructor. It's ok. But I can't understand why this code also crash at r2 destructor, r2 created in main and delete…
micdelt
  • 21
  • 3
0
votes
2 answers

What will be an efficient way of converting a std::vector to a std::vector

I can use a loop to copy elements from boost::any vector to std::vector of floats. It is inefficient in the sense that there are 50000 values to copy, vector can grow beyond 50K and I have to save the to the disk in different folders. So it is a…
Wajih
  • 793
  • 3
  • 14
  • 31
0
votes
1 answer

Template cast operator and boost::any or std::any

I wrote a generic class to provide an easy JSON-based init to any class. It was working like a charm until I want to apply it to a class that contain an enum. my base class first parse the JSON, find the sub object of the JSON that have the same…
alexbuisson
  • 7,699
  • 3
  • 31
  • 44
0
votes
1 answer

C++ Templates access a function with different types

So What I'm trying to do is something like this. I have a template struct like this one: template struct TemplateTest { void test(T a) { switch (typeid(boost::any_cast(a))) { case typeid(int): …
Vali
  • 629
  • 2
  • 6
  • 14