blob: 2eba8e7428af195b7336ce59ae5c85e665716534 [file] [log] [blame]
Marshall Clow354d39c2014-01-16 16:58:45 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Howard Hinnant3e519522010-05-11 19:42:16 +000010#ifndef MOVEONLY_H
11#define MOVEONLY_H
12
Eric Fiselierf2f2a632016-06-14 21:31:42 +000013#include "test_macros.h"
14
Eric Fiselier9adebed2017-04-19 01:02:49 +000015#if TEST_STD_VER >= 11
Howard Hinnant3e519522010-05-11 19:42:16 +000016
17#include <cstddef>
18#include <functional>
19
20class MoveOnly
21{
22 MoveOnly(const MoveOnly&);
23 MoveOnly& operator=(const MoveOnly&);
24
25 int data_;
26public:
David Blaikiec6dbc222014-08-09 22:42:19 +000027 MoveOnly(int data = 1) : data_(data) {}
28 MoveOnly(MoveOnly&& x)
29 : data_(x.data_) {x.data_ = 0;}
30 MoveOnly& operator=(MoveOnly&& x)
31 {data_ = x.data_; x.data_ = 0; return *this;}
Howard Hinnant3e519522010-05-11 19:42:16 +000032
33 int get() const {return data_;}
34
Howard Hinnant8f2f7e72010-08-22 00:15:28 +000035 bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
36 bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
Billy Robert O'Neal III3770e402018-01-05 01:32:00 +000037 MoveOnly operator+(const MoveOnly& x) const { return MoveOnly{data_ + x.data_}; }
38 MoveOnly operator*(const MoveOnly& x) const { return MoveOnly{data_ * x.data_}; }
Howard Hinnant3e519522010-05-11 19:42:16 +000039};
40
41namespace std {
42
43template <>
44struct hash<MoveOnly>
Howard Hinnant3e519522010-05-11 19:42:16 +000045{
Eric Fiselierae2c8de2017-01-18 01:48:54 +000046 typedef MoveOnly argument_type;
47 typedef size_t result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +000048 std::size_t operator()(const MoveOnly& x) const {return x.get();}
49};
50
51}
52
Eric Fiselier9adebed2017-04-19 01:02:49 +000053#endif // TEST_STD_VER >= 11
Howard Hinnant3e519522010-05-11 19:42:16 +000054
Howard Hinnant8f2f7e72010-08-22 00:15:28 +000055#endif // MOVEONLY_H