Boost logo

Boost :

Subject: Re: [boost] yomm2 - open methods
From: Jean-Louis Leroy (jl_at_[hidden])
Date: 2018-01-21 00:54:41


OK after adding a bit of flexibility, and then taking advantage of it,
I could make this work:

using Any = any<mpl::vector<copy_constructible<>, typeid_<>, relaxed> >;

declare_method(string, type, (virtual_<Any>));

begin_method(string, type, (int value)) {
    return "int " + std::to_string(value);
} end_method;

register_class(Any);
register_class(int, Any); // I guess...

struct Animal {};

BOOST_AUTO_TEST_CASE(type_erasure)
{
    //yorel::yomm2::detail::log_on(&std::cerr);
    yorel::yomm2::update_methods();
    Any x(10);
    BOOST_TEST(type(x) == "int 10");
}

(complete code at here:
https://github.com/jll63/yomm2/blob/boost-type-erasure/tests/boost_type_erasure.cpp#L69)

I feel a bit uneasy though.

If yomm2 ever becomes a part of Boost, I do see the value of making it
play ball with other Boost libraries.

On the other hand...one of my major sources of inspiration is the
paper by Pirkelbauer, Solodkyy and Stroustrup (the other being CLOS).
I try to emulate the proposed syntax and functionality that they
describe, in the hope that people get to try open methods, start
liking them and, eventually, they become part of the language.

So this is quite a stretch. That being said, I already drift from the
paper by supporting std::shared_ptr virtual parameters...and my Matrix
example shows that open methods without support for smart pointers
would miss some important use cases.


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