如何创建提升凤凰make_shared? [英] how to create boost phoenix make_shared?

查看:144
本文介绍了如何创建提升凤凰make_shared?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能创建的std :: make_shared的提升凤凰懒变种?我的意思是,要尽可能像

Is it possible to create boost phoenix lazy variant of std::make_shared ? I mean, to make possible something like

命名空间P =提振::凤;结果
...结果
EXPR = custom_parser [_a = P :: make_shared<节点>(_ 1,_2,_3)] >> ...

一个不能使用BOOST_PHOENIX_ADAPT_FUNCTION因为性病的可变参数模板性质:: make_shared。因此,可能是包装应可变参数模板本身,如果是可以写入之一。

One cannot use BOOST_PHOENIX_ADAPT_FUNCTION because of variadic template nature of std::make_shared. So, probably wrapper should be variadic template itself, if it is possible to write one.

推荐答案

如果您能抽出一组额外的括号:

If you can spare an extra set of parentheses:

namespace {
    template <typename T>
    struct make_shared_f
    {
        template <typename... A> struct result 
            { typedef boost::shared_ptr<T> type; };

        template <typename... A>
        typename result<A...>::type operator()(A&&... a) const {
            return boost::make_shared<T>(std::forward<A>(a)...);
        }
    };

    template <typename T>
    using make_shared_ = boost::phoenix::function<make_shared_f<T> >;
}

您可以使用像

typedef std::vector<int> IntVec;
auto LazyInts = make_shared_<IntVec>()(arg1, arg2);

// create a shared vector of 7 ints '42'
auto ints = LazyInts(7, 42);
for (auto i : *ints) std::cout << i << " ";

看它的 住在Coliru

See it Live on Coliru

这篇关于如何创建提升凤凰make_shared?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆