pol*_*eme 5 c++ boost boost-phoenix make-shared
有可能创建boost phoenix lazy变种std::make_shared吗?我的意思是,做一些类似的事情
namespace p = boost::phoenix;
...
expr = custom_parser[_a=p::make_shared<Node>(_1,_2,_3)] >> ...
Run Code Online (Sandbox Code Playgroud)
BOOST_PHOENIX_ADAPT_FUNCTION由于可变模板的性质,人们无法使用std::make_shared.所以,如果有可能写一个包装器,那么包装器应该是variadic模板本身.
如果你可以省去一组额外的括号:
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> >;
}
Run Code Online (Sandbox Code Playgroud)
您可以使用哪种
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 << " ";
Run Code Online (Sandbox Code Playgroud)
在科利鲁看到它