I have the following test application:
#include <boost/any.hpp>
#include <iostream>
void check(boost::any y)
{
if (y.empty())
std::cout << "empty!\n";
else
std::cout << "Not empty, type: " << y.type().name() << "\n";
}
int main()
{
boost::any boostAny;
check(boostAny);
boost::any* boostAny2 = &boostAny;
check(boostAny2);
boost::any* boostAny3 = new boost::any;
check(boostAny3);
delete(boostAny3);
}
I compile and run like so:
g++ -std=c++11 -o test test.cpp && ./test
Output is:
empty!
Not empty, type: PN5boost3anyE
Not empty, type: PN5boost3anyE
I would expect for all 3 tests the same output. But it's not. Why? Is this a bug? Tried with boost 1.54.0 and 1.55.0.
boostAny2is a pointer toboost::any. You pass it as parameter tocheck, which expects aboos::any, so a newboost::anyinstance is created from theboost::any*(ie. the value type will beboost::any*). Ref. https://www.boost.org/doc/libs/release/doc/html/boost/any.htmlOr in other words, what's actually happening is (conceptually) :
Maybe you meant instead :
The same applies to
boostAny3.