使用VS 2015社区编译boost.type_erasure时出现模糊调用

时间:2015-08-31 12:10:17

标签: c++ boost boost-type-erasure

我尝试在免费功能`foo'上使用boost.type_erasure(版本1.59),如下所示。

#include <boost/type_erasure/any.hpp>
#include <boost/type_erasure/free.hpp>

void Foo(int);

BOOST_TYPE_ERASURE_FREE((HasFoo), Foo, 1)

using Type = boost::type_erasure::any<
    HasFoo<void(boost::type_erasure::_self const&)>,
    boost::type_erasure::_self const&
>;

void Foo(int) {}

int main() {
    Type x{ 1 };
    Foo(x);

    return 0;
}

根据我对GCC和CLang对coliru的测试进行编译。但是,VS 2015社区提供了以下错误消息。

Source.cpp
Source.cpp(17): error C2668: 'boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo': ambiguous call to overloaded function
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,boost::type_erasure::_self &&>>
        ]
Source.cpp(6): note: could be 'void boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo(eval_if_c<0,boost::type_erasure::detail::maybe_const_this_param<const boost::type_erasure::_self &,Base>,boost::type_erasure::as_param<Base,const boost::type_erasure::_self &>>::type)' [found using argument-dependent lookup]
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,boost::type_erasure::_self &&>>
        ]
Source.cpp(6): note: or       'void boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo(eval_if_c<0,boost::type_erasure::detail::maybe_const_this_param<const boost::type_erasure::_self &,Base>,boost::type_erasure::as_param<Base,const boost::type_erasure::_self &>>::type)' [found using argument-dependent lookup]
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,boost::type_erasure::_self &>>
        ]
Source.cpp(6): note: or       'void boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo(eval_if_c<0,boost::type_erasure::detail::maybe_const_this_param<const boost::type_erasure::_self &,Base>,boost::type_erasure::as_param<Base,const boost::type_erasure::_self &>>::type)' [found using argument-dependent lookup]
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,boost::type_erasure::_self>>
        ]
Source.cpp(6): note: or       'void boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo(eval_if_c<0,boost::type_erasure::detail::maybe_const_this_param<const boost::type_erasure::_self &,Base>,boost::type_erasure::as_param<Base,const boost::type_erasure::_self &>>::type)' [found using argument-dependent lookup]
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,const boost::type_erasure::_self &>>
        ]
Source.cpp(13): note: or       'void Foo(int)'
Source.cpp(17): note: while trying to match the argument list '(Type)'

1 个答案:

答案 0 :(得分:0)

根据Boost-users邮件列表的响应,它是由VS的可变参数模板错误引起的。代码通过定义BOOST_NO_CXX11_VARIADIC_TEMPLATES进行编译。