Boost logo

Boost :

Subject: Re: [boost] [any] new version
From: Artyom Beilis (artyomtnk_at_[hidden])
Date: 2011-09-02 08:28:55


> From: Martin Bidlingmaier <Martin.Bidlingmaier_at_[hidden]>
>
> I've written a new version of boost::any. It does not
> depend on rtti and uses a static integer value instead of
> std::type_info to store type information.

Please don't do this!

unsigned int next_id()
{
    static unsigned int previous_id = 0; //0 is not assigned to a type

    ++previous_id;
    return previous_id;
}

But what is even more horrible that it would not
work on DLL platform without making Boost.Any non-header only
library:

Example:

/tmp/any$ cat dll.cpp
#include "any.hpp"

__declspec(dllexport) boost::proposal::any get_int()
{
        boost::proposal::any a = int(10);
        return a;
}
/tmp/any$ cat main.cpp
#include "any.hpp"
#include <iostream>

__declspec(dllimport) boost::proposal::any get_int();

int main()
{
        boost::proposal::any d=double(3.14);
        boost::proposal::any i=get_int();
        try {
                std::cout << boost::proposal::any_cast<double>(d) << std::endl;
                std::cout << boost::proposal::any_cast<int>(i) << std::endl;
        }
        catch(std::exception const &e) {
                std::cerr << e.what() << std::endl;
        }
}

/tmp/any$ wine ./a.exe
3.14
boost::bad_any_cast: failed conversion using boost::any_cast

And you can't solve this without making any compiled library...

So please....

--------------------
Do not reinvent RTTI
--------------------

Best,

Artyom Beilis
--------------
CppCMS - C++ Web Framework: http://cppcms.sf.net/
CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk