using lexical_cast with tuples.

Hello, I'm guessing this has something to do with the unsetf(std::ios::skipws) call. Anyway, the following code seems contradictory since it's output is "Exception Thrown". Has anyone else come across this? #include <iostream> #include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple_io.hpp> #include <boost/lexical_cast.hpp> int main() { boost::tuple<float,float> aTuple(2.2f,3.3f); std::string theString = boost::lexical_cast<std::string>(aTuple); try { boost::tuple<float,float> i = boost::lexical_cast<boost::tuple<float,float> > ( theString ); } catch(...) { std::cout << "Exception Thrown" << std::endl; } } Thanks, David J. Sankel

Is there an easy way to write: template <typename T> struct is_variant { typedef ??? type; }; So far the best I can come up with is: 1) T has a member type "types" and 2) T is convertible to make_variant_over<T::types>::type and 3) make_variant_over<T::types>::type is convertible to T Does anyone have a better idea? Thanks!

On Thu, Feb 05, 2004 at 06:28:27PM -0600, Brock Peabody wrote:
Is there an easy way to write:
template <typename T> struct is_variant {
typedef ??? type; };
So far the best I can come up with is:
1) T has a member type "types" and 2) T is convertible to make_variant_over<T::types>::type and 3) make_variant_over<T::types>::type is convertible to T
Does anyone have a better idea?
Perhaps I'm missing something, but why not just something like template <typename T> struct is_variant { typedef false_ type; }; template <typename T1, typename T2, ... /*however many*/> struct is_variant<variant<T1,T2,...> > { typedef true_ type; }; ? -- -Brian McNamara (lorgon@cc.gatech.edu)

Brian McNamara wrote:
On Thu, Feb 05, 2004 at 06:28:27PM -0600, Brock Peabody wrote:
Is there an easy way to write:
template <typename T> struct is_variant {
typedef ??? type; };
So far the best I can come up with is:
1) T has a member type "types" and 2) T is convertible to make_variant_over<T::types>::type and 3) make_variant_over<T::types>::type is convertible to T
Does anyone have a better idea?
Perhaps I'm missing something, but why not just something like
template <typename T> struct is_variant { typedef false_ type; }; template <typename T1, typename T2, ... /*however many*/> struct is_variant<variant<T1,T2,...> > { typedef true_ type; };
?
Precisely, template <typename T> struct is_variant : mpl::false_ {}; template <BOOST_VARIANT_ENUM_PARAMS(typename T)> struct is_variant< variant<BOOST_VARIANT_ENUM_PARAMS(T)> > : mpl::true_ {}; should do the trick. If this is deemed useful, I can include it in the next release. For now, BOOST_VARIANT_ENUM_PARAMS should cover you. Eric

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Eric Friedman
template <typename T> struct is_variant : mpl::false_ {};
template <BOOST_VARIANT_ENUM_PARAMS(typename T)> struct is_variant< variant<BOOST_VARIANT_ENUM_PARAMS(T)> > : mpl::true_ {};
should do the trick. If this is deemed useful, I can include it in the next release. For now, BOOST_VARIANT_ENUM_PARAMS should cover you.
Yes that's much better. I don't know why I was making it so difficult. Thanks!
participants (4)
-
Brian McNamara
-
Brock Peabody
-
David Sankel
-
Eric Friedman