2014-11-01 22:12:11 +09:00
|
|
|
/*=============================================================================
|
|
|
|
Copyright (c) 2008 Joel de Guzman
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
==============================================================================*/
|
2014-10-08 23:57:55 +09:00
|
|
|
#include <boost/config.hpp>
|
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && \
|
|
|
|
!defined(BOOST_NO_CXX11_SMART_PTR)
|
|
|
|
|
2014-09-27 13:22:56 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <tuple>
|
2008-08-20 08:20:19 +00:00
|
|
|
#include <boost/any.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace Core
|
|
|
|
{
|
|
|
|
class AutoConverter
|
|
|
|
{
|
2014-09-27 13:22:56 +01:00
|
|
|
std::shared_ptr<boost::any> t_;
|
2008-08-20 08:20:19 +00:00
|
|
|
|
|
|
|
public:
|
2014-09-27 13:22:56 +01:00
|
|
|
AutoConverter(std::shared_ptr<boost::any> const & t)
|
2008-08-20 08:20:19 +00:00
|
|
|
: t_(t)
|
|
|
|
{}
|
|
|
|
|
|
|
|
template <typename C>
|
|
|
|
operator C ()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
boost::any & a = (*t_);
|
|
|
|
|
|
|
|
return boost::any_cast<C>(a);
|
|
|
|
}
|
|
|
|
catch(boost::bad_any_cast & e)
|
|
|
|
{
|
|
|
|
std::cerr << "Internal conversion bug: "
|
|
|
|
<< "Failed to convert data holder to "
|
|
|
|
<< typeid(C).name() << "\n"
|
|
|
|
<< e.what()
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
C c = C();
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline AutoConverter Demo()
|
|
|
|
{
|
2014-09-27 13:22:56 +01:00
|
|
|
std::shared_ptr<boost::any> p_result
|
|
|
|
(new boost::any(std::make_tuple(1, 2, 3, 4)));
|
2008-08-20 08:20:19 +00:00
|
|
|
return p_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Core
|
|
|
|
|
|
|
|
|
2010-06-12 15:58:31 +00:00
|
|
|
int main()
|
2008-08-20 08:20:19 +00:00
|
|
|
{
|
2014-09-27 13:22:56 +01:00
|
|
|
std::tuple<int, int, int, int> test = Core::Demo();
|
2008-08-20 08:20:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-08 23:57:55 +09:00
|
|
|
#else
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|