Heterogenous link list

does anybody know about heterogenous link list ? how we could implement ?
Use a discriminated union - for example, boost::any
http://www.boost.org/doc/libs/1_50_0/doc/html/any.html

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
#include <boost/any.hpp>
#include <list>
#include <typeinfo>
#include <iostream>

int main()
{
    int i = 8 ;
    double d = 29.46 ;
    std::string str = "abcd" ;

    std::list< boost::any > list ;
    list.push_back(i) ;
    list.push_back(d) ;
    list.push_back(str) ;

    for( const boost::any& any : list )
    {
        const auto& type = any.type() ;

        if( type == typeid(int) )
            std::cout << boost::any_cast<int>(any) << '\n' ;
        else if( type == typeid(double) )
            std::cout << boost::any_cast<double>(any) << '\n' ;
        else if( type == typeid(std::string) )
            std::cout << boost::any_cast<std::string>(any) << '\n' ;
        else
            std::cout << "unhandled type\n" ;
    }

}
Thanx for your reply.. do i need anything for using boost.any.hpp?
> do i need anything for using boost.any.hpp?

Like almost everything in boost, boost.any is a header only library.

On the build machine, you need to have the boost headers as one of the directories where #include <> files are looked for.

On the target machine, you need nothing other than your executable.
ok Thank you for help..
Topic archived. No new replies allowed.