Files
spark/src/lib/utils/ValueWrapper.h
T

55 lines
1.3 KiB
C++

#pragma once
#include <utility>
#include <ostream>
namespace bts {
namespace utils {
template <class Tag,class ValueT>
class ValueWrapper {
public:
typedef ValueT Value;
ValueWrapper() : _v() {}
explicit ValueWrapper(ValueT const&v) : _v(v) {}
explicit ValueWrapper (ValueT &&v) : _v (std::move(v)) {}
ValueWrapper(ValueWrapper const&v) : _v (v._v) {}
ValueWrapper(ValueWrapper &&v) : _v (std::move(v._v)) {}
ValueWrapper &operator=(ValueWrapper const&v) {_v = v._v;return *this;}
ValueWrapper &operator=(ValueWrapper &&v) {_v = std::move(v._v);return *this;}
bool operator==(ValueWrapper const&v) const {return _v == v._v;}
bool operator!=(ValueWrapper const&v) const {return _v != v._v;}
bool operator<(ValueWrapper const&v) const {return _v < v._v;}
bool operator>(ValueWrapper const&v) const {return _v > v._v;}
ValueT const& value() const {return _v;}
ValueT & value() {return _v;}
private:
ValueT _v;
};
// don't ask.
template <class Tag, class V>
std::ostream& operator<<(std::ostream &s, ValueWrapper<Tag,V> const&v)
{
s << v.value();
return s;
}
}}
namespace std {
template <typename Tag, typename Value>
struct hash<bts::utils::ValueWrapper<Tag,Value>>
{
std::size_t operator()(const bts::utils::ValueWrapper<Tag,Value> & k) const
{
return hash<Value>()(k.value());
}
};
}