aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-23 21:51:14 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-23 21:51:14 +0100
commitdb798f9e36404906bcd1253c9410169de122fefb (patch)
tree3f161c37283c7a9ee107749757b022fb8381ec48
parent1e88d3f531a7d9cac4cd08db1484a3a87679af3c (diff)
downloadpaludis-db798f9e36404906bcd1253c9410169de122fefb.tar.gz
paludis-db798f9e36404906bcd1253c9410169de122fefb.tar.xz
Make use of rvalue refs
-rw-r--r--paludis/util/named_value.hh26
1 files changed, 26 insertions, 0 deletions
diff --git a/paludis/util/named_value.hh b/paludis/util/named_value.hh
index f78851f..bf61198 100644
--- a/paludis/util/named_value.hh
+++ b/paludis/util/named_value.hh
@@ -22,6 +22,8 @@
#include <paludis/util/named_value-fwd.hh>
#include <paludis/util/tribool-fwd.hh>
+#include <utility>
+#include <type_traits>
#include <string>
namespace paludis
@@ -47,6 +49,8 @@ namespace paludis
template <typename K_, typename V_>
class NamedValue
{
+ static_assert(! std::is_reference<V_>::value, "Tried to make a NamedValue hold a reference");
+
private:
V_ _value;
@@ -60,16 +64,32 @@ namespace paludis
{
}
+ template <typename T_>
+ NamedValue(NamedValue<K_, T_> && v) :
+ _value(std::move(v()))
+ {
+ }
+
explicit NamedValue(const V_ & v) :
_value(v)
{
}
+ explicit NamedValue(V_ && v) :
+ _value(v)
+ {
+ }
+
NamedValue(const NamedValue & v) :
_value(v._value)
{
}
+ NamedValue(NamedValue && v) :
+ _value(std::move(v._value))
+ {
+ }
+
V_ & operator() ()
{
return _value;
@@ -96,6 +116,12 @@ namespace paludis
return NamedValue<Name<T_>, V_>(v);
}
+ template <typename V_>
+ NamedValue<Name<T_>, typename std::remove_reference<V_>::type> operator= (V_ && v) const
+ {
+ return NamedValue<Name<T_>, typename std::remove_reference<V_>::type>(v);
+ }
+
NamedValue<Name<T_>, std::string> operator= (const char * const v) const
{
return NamedValue<Name<T_>, std::string>(std::string(v));