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
0
votes
2 answers

Boost::any not empty when used from a pointer

I have the following test application: #include #include void check(boost::any y) { if (y.empty()) std::cout << "empty!\n"; else std::cout << "Not empty, type: " << y.type().name() << "\n"; } int…
Veda
  • 2,025
  • 1
  • 18
  • 34
0
votes
1 answer

boost::any with structs and unsigned ints

There are several parts to my question. I have been researching on how/when to use boost::any. I was wondering if it is possible to assign a struct to a boost::any variable. Example: struct S { int x; }; S s; s.x = 5; boost::any var = s; It…
demogorgon
  • 474
  • 4
  • 20
0
votes
1 answer

boost::unsafe_any_cast invalid non-null pointer when empty?

I've got a piece of code in which I use boost::unsafe_any_cast(&boost::any anyInstance) to obtain the content pointer of a boost::any object. The code is this below: boost::any staticResult; //contains a private pointer called…
XectX
  • 36
  • 4
0
votes
0 answers

Different behaviour if type is a reference

I'm using the function tryValue very often in my projects. It is simple wrapper around boost::any, that simplifies greatly its everyday usage. #include #include #include #include…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
0
votes
1 answer

Using Eigen::LLT within a templated function

I have written the following function: template inline static boost::any ApplyCholesky(boost::any const& A, boost::any const& x) { const Eigen::LLT& chol = boost::any_cast
ad_ad
  • 375
  • 3
  • 14
0
votes
1 answer

Why does this type erasure implementation (simplified boost:any) gives segmentation fault?

I was trying my own implementation of a generic container of arbitrary type (similar to boost:any) just to learn about the idiom, and I am trying to understand why my code gives a segmentation fault. class IValue { public: IValue() = default; …
bone
  • 144
  • 2
  • 6
0
votes
1 answer

Type checking of std::map of keys and/or values of type boost::any?

I am writing helper functions which converts DBus properties values to std types. For that, to convert few type, i need to create a std::map. The map will represent DICT type in DBus. The DICT type in DBUS can have any type as a key and any type as…
abhiarora
  • 9,743
  • 5
  • 32
  • 57
0
votes
1 answer

Heterogeneous HashMap c++

I have different data types which I'm trying to save in one HashMap. The HashMap will be created inside a variable arguments function. Unions under struct and Boost::Any didn't work for me, Unions don't accept classes as data types. Boost::any gives…
sudhansh_
  • 125
  • 1
  • 2
  • 14
0
votes
0 answers

Comparator for boost::any underlying type

I have a struct that is used for Tokenizing a byte stream (std::vector). The stream can contain bytes, words, dwords, null-terminated strings and raw data. struct Token { enum TokenClass { BYTE, WORD, INT, SZCHAR, DATA …
graham.reeds
  • 16,230
  • 17
  • 74
  • 137
0
votes
1 answer

C++: How to create a vector storing vectors of any type?

I'd like to store vectors of any type in another vector. So, for example I have two vector instances, "std::vector v1" and "std::vector v2". And I would like to put them into a vector. I already tried like this: std::vector
Maahly
  • 15
  • 1
  • 9
0
votes
2 answers

std::unordered_map throws annoying compile errors

When I declare a variable of std::unordered_map type, it throws annoying compile errors. For an example, any.cc: #include #include int main() { std::map dict; return…
signal
  • 424
  • 6
  • 23
0
votes
3 answers

boost::any confusion with pointers vs values

It took me a while to figure this out, but the semantics of boost::any are confusing. With value types, you use it like so: int value = 100; boost::any something; something = value; //...later... int value = boost::any_cast(&something); This…
void.pointer
  • 24,859
  • 31
  • 132
  • 243
0
votes
0 answers

Trying to use boost::serialization of Boost::any

I am trying to work with boost::serialisation for saving and loading some objects. So far from the boost::tutorial I have managed to do things work for all the different stl stuff (vectors, pairs, lists etc), for derived classes, for boost…
user3111197
  • 83
  • 2
  • 11
0
votes
1 answer

Overload operator == for STL container

I'm trying to remove a class object from list l l.remove(class_type); I tried writing something like this as a member function bool operator == (const class_type &a) const //not sure about the arguments { //return bool value } How…
cpx
  • 17,009
  • 20
  • 87
  • 142
0
votes
3 answers

casting pointers

I'm using ptr_map for storing different types of pointers. boost::ptr_map someMap; I store there some templated class objects: someMap.insert("1", new SomeClass()); someMap.insert("2", new SomeClass()); Now I want to get…
Max Frai
  • 61,946
  • 78
  • 197
  • 306