3
在升壓::原手冊中,有::變換< ...>匹配類型爲std終端的語法的例子:我可以知道在變換中匹配boost :: proto :: _的類型嗎?
struct StdComplex
: proto::terminal< std::complex<proto::_> >
{};
我想編寫一個轉換,做一些事proto :: _的類型。 例如,當匹配proto :: terminal < std :: complex < T>>時,它會返回boost :: shared_ptr < T>。
這可能嗎?
陳述我的問題的另一種方法是,我如何使下面的代碼段工作?
template<typename T>
struct Show : proto::callable
{
typedef T result_type;
result_type operator()(T& v)
{
std::cout << "value = " << v << std::endl;
return v;
}
};
struct my_grammar
: proto::when<proto::terminal<proto::_ >, Show<??? what comes here ???>(proto::_value) >
{};
謝謝 - 很優雅! – 2012-02-16 20:23:49
這似乎適用於 proto :: terminal :: type term1 = {{21}}; 但不是 proto :: terminal :: type term1 = {{21}}; 對嗎?在我的應用程序中,我希望終端擁有一個shared_ptr,它指向可以修改的東西。這是一個問題嗎?謝謝。 –
2012-02-25 11:49:29
我從非const int的編譯器中得到的錯誤是: 類型'int'的非常量左值引用無法綁定到'int'類型的臨時值。 – 2012-02-25 11:52:16