Boost logo

Boost Users :

Subject: [Boost-users] Boost.Type_erasure: member function return _self
From: Yuan Yao (yaoyuan0123_at_[hidden])
Date: 2015-11-25 09:16:26


I want to use Boost.Type_erasure on a member function that returns the type itself. With _self as the return type, it is OK. However, when the return type changes to pair<_self, some_type>, an error occurs. The following code reproduces the problem.

#include <utility>
#include <boost/type_erasure/any.hpp>
#include <boost/type_erasure/member.hpp>

BOOST_TYPE_ERASURE_MEMBER((HasTest1), Test1, 0)
BOOST_TYPE_ERASURE_MEMBER((HasTest2), Test2, 0)

using boost::type_erasure::_self;
using std::pair;
using Type1 = boost::type_erasure::any<
    boost::mpl::vector<
    boost::type_erasure::copy_constructible<>,
    HasTest1<_self(), _self const>
    >,
    _self
>;
using Type2 = boost::type_erasure::any<
    boost::mpl::vector<
    boost::type_erasure::copy_constructible<>,
    HasTest2<pair<_self, int>(), _self const>
    >,
    _self
>;

int main() {
    struct test {
        test Test1() const { throw; }
        pair<test, int> Test2() const { throw; }
    };

    Type1{ test{} };// OK
    Type2{ test{} };// Error
}

How can I fix this problem without using return arguments?

Sample error message:

main.cpp:6:1: error: no viable conversion from 'pair<test, [...]>' to 'pair<boost::type_erasure::_self, [...]>'

BOOST_TYPE_ERASURE_MEMBER((HasTest2), Test2, 0)

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net