本文介绍了R ++在C ++ 03的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何判断给定参数是否为C ++ 03中的右值?我写了一些非常通用的代码,如果可能的话需要参考,否则构造一个新的对象。我可以重载以取值以及by-reference和rvalue返回调用by-value函数?



或者我有一个非常恶心的感觉这是为什么右值引用是在C ++ 0x?



编辑:



is_rvalue =!显然有一种方法可以确定一个表达式是否为C ++ 03中的右值或左值(如果是这样的话):

我说明显是因为我不知道我是多么理解的技术)。注意,为了使该技术可用,预处理器宏是非常需要的。 Eric Niebler撰写了一篇关于它如何工作以及如何在BOOST_FOREACH中使用的文章:







注意这篇文章是相当沉重的阅读(至少是对我来说);正如Neibler所说:

使用artcile中描述的rvalue检测可能会帮助您处理任何表达式的至少一些C ++ 0x的右值引用解析的问题。


How can you tell whether or not a given parameter is an rvalue in C++03? I'm writing some very generic code and am in need of taking a reference if possible, or constructing a new object otherwise. Can I overload to take by-value as well as by-reference and have the rvalue returns call the by-value function?

Or do I have a very sickening feeling that this is why rvalue references are in C++0x?

Edit:

is_rvalue = !(is_reference || is_pointer) ?

解决方案

There apparently is a way to determine whether an expression is an rvalue or lvalue in C++03 (I say apparently because I'm not sure how well I understand the technique). Note that to make the technique usable, preprocessor macros are pretty much required. Eric Niebler has written a nice article about how it works and how it gets used in BOOST_FOREACH:

Note that the article is pretty heavy reading (at least it is for me); as Neibler says in it:

Using the rvalue detection described in the artcile might help you deal with at least some of the issues that C++0x's rvalue references solve.

这篇关于R ++在C ++ 03的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 07:46