0

I have a variable boost::any* items. My requirement is to:

assign items with list of values which can be of type int,double or any other datatype. But at a given time the data-type will be unique.

The issue:

For single values i can assign using items[index] = value; But if i do item = values; where values is a double array it cannot automatically cast. Also if i use

items = boost::any_cast<boost::any*>(values)

I receive 'boost::bad_any_cast': failed conversion using 'boost::any_cast`.

Some hints will be really great about how can i cast a double array to boost::any array.

Pinaki
  • 1
  • 1
  • One more update, if i use items = reinterpret_cast(values); the program runs and i can also assign the values. But boost::any_cast(this->entries[_index]) gives an error for bad cast from boost. So i am not able to retreive the values back. – Pinaki Nov 09 '12 at 12:43

1 Answers1

1

It just can't work. In a double[], the doubles are contiguous. There's no space between two doubles. Roughly the same applies for a boost::any[] : there's no space between two any objects. But there IS space between the two doubles stored inside adjacent boost::any<> wrappers.

You'll have to write a function.

MSalters
  • 173,980
  • 10
  • 155
  • 350