thelink2012 / any

Implementation of std::experimental::any, including small object optimization, for C++11 compilers
Boost Software License 1.0
144 stars 37 forks source link

Added any_cast_test, don't throw on failed pointer cast, equality operator #6

Open eligt opened 7 years ago

eligt commented 7 years ago

I've added a few features to the class, I know these are not in the standard so I don't expect you to merge them into master but putting them here in case someone else needs them.

I think in most situations, if you're using any for storage, you don't know the type in advance so you want to check what type it is and exceptions are way too inconvenient (and slow), so I've added any_cast_test that returns a bool determining the success of the cast.

I've also adjusted any_cast to not throw an exception in case the type stored is a pointer (it returns nullptr instead).

Finally I've added an equality operator so you can test whether two different any instances contain the same data (either the same pointer or same value).