summaryrefslogtreecommitdiff
path: root/libs/fusion/test/sequence/tr1_tuple_auto_conv.cpp
blob: 010d4c710cec0e3df2493375e094bae6f0570864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <boost/tr1/memory.hpp>
#include <boost/tr1/tuple.hpp>
#include <boost/any.hpp>
#include <iostream>

namespace Core
{
    class AutoConverter
    {
        std::tr1::shared_ptr<boost::any> t_;

    public:
        AutoConverter(std::tr1::shared_ptr<boost::any> const & t)
            : 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()
    {
        std::tr1::shared_ptr<boost::any> p_result
            (new boost::any(std::tr1::make_tuple(1, 2, 3, 4)));
        return p_result;
    }

} // namespace Core


int main()
{
    std::tr1::tuple<int, int, int, int> test = Core::Demo();
    return 0;
}