
On Wed, Jul 9, 2008 at 9:57 PM, Mathias Gaunard wrote:
Ferdinand Prantl wrote:
I would like to improve usage of boost::any with text (char*) constants. This would be the goal:
boost::any foo("foo");
This is not a char*. There is no problem putting a char* in a boost::any. It's a const char[N]. An array. To insert an object into a boost::any, the object needs to be copyable. Arrays aren't. The end.
I were not arguing the type of the expression. The thing was - is it possible to modify boost::any in some way to make it usable with C-string style constants without a cast? By the way, there is a problem with the proposal made in my previous e-mail. It would be virtually impossible to get the value from the object by a cast if the array was stored with its exact type. It is much easier to store it as a pointer. The only working option that remains me would be to accept pointers passed to constructor and to assignment operator as an array either/or: template<typename ValueType> any(const ValueType * value) : content(new holder<const ValueType *>(value)) { } template<typename ElementType, std::size_t NumberOfElements> any(const ElementType (& value)[NumberOfElements]) : content(new holder<const ElementType *>(value)) { } Yes, it would mean that boost::any does not accept only copyable objects, it would enable arays too and it would handle them as a const pointer to their first element. Would it be bad? Thanks, Ferda