
On 2010-09-01 14:13, Roman Perepelitsa wrote:
2010/9/1 Roland Bock <rbock@eudoxos.de <mailto:rbock@eudoxos.de>>
Hi,
is there something in Boost.TypeTraits (or somewhere else) that allows me to check if a type is a boost::optional?
I'd like to do something like this:
template<typename T> typename enable_if<is_boost_optional<T> >, T::value_type>::type foo(const T&);
You can use is_instance_of from lambda library (see boost/lambda/detail/is_instance_of.hpp). It's not part of public interface though, so use it on your own risk.
template <class T> struct is_boost_optional : boost::lambda::is_instance_of_1<T, boost::optional> {}
Roman Perepelitsa.
This seems to work, too: // ------------------------------------------------------------- template <typename T, typename Enable = void> class is_boost_optional { public: static const bool value = false; }; template <typename T> class is_boost_optional < T, typename boost::enable_if < boost::is_same < boost::optional<typename T::value_type>, T > >::type > { public: static const bool value = true; }; // ------------------------------------------------------------- Regards, Roland