blob: 5611ebbdd3a1dc0ae94b3b64d416ba71d9d91fe8 [file] [log] [blame]
Marshall Clow354d39c2014-01-16 16:58:45 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Marshall Clow354d39c2014-01-16 16:58:45 +00006//
7//===----------------------------------------------------------------------===//
8
Howard Hinnant3e519522010-05-11 19:42:16 +00009#ifndef MOVEONLY_H
10#define MOVEONLY_H
11
Eric Fiselierf2f2a632016-06-14 21:31:42 +000012#include "test_macros.h"
13
Eric Fiselier9adebed2017-04-19 01:02:49 +000014#if TEST_STD_VER >= 11
Howard Hinnant3e519522010-05-11 19:42:16 +000015
16#include <cstddef>
17#include <functional>
18
19class MoveOnly
20{
21 MoveOnly(const MoveOnly&);
22 MoveOnly& operator=(const MoveOnly&);
23
24 int data_;
25public:
David Blaikiec6dbc222014-08-09 22:42:19 +000026 MoveOnly(int data = 1) : data_(data) {}
27 MoveOnly(MoveOnly&& x)
28 : data_(x.data_) {x.data_ = 0;}
29 MoveOnly& operator=(MoveOnly&& x)
30 {data_ = x.data_; x.data_ = 0; return *this;}
Howard Hinnant3e519522010-05-11 19:42:16 +000031
32 int get() const {return data_;}
33
Howard Hinnant8f2f7e72010-08-22 00:15:28 +000034 bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
35 bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
Billy Robert O'Neal III3770e402018-01-05 01:32:00 +000036 MoveOnly operator+(const MoveOnly& x) const { return MoveOnly{data_ + x.data_}; }
37 MoveOnly operator*(const MoveOnly& x) const { return MoveOnly{data_ * x.data_}; }
Howard Hinnant3e519522010-05-11 19:42:16 +000038};
39
40namespace std {
41
42template <>
43struct hash<MoveOnly>
Howard Hinnant3e519522010-05-11 19:42:16 +000044{
Eric Fiselierae2c8de2017-01-18 01:48:54 +000045 typedef MoveOnly argument_type;
46 typedef size_t result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +000047 std::size_t operator()(const MoveOnly& x) const {return x.get();}
48};
49
50}
51
Eric Fiselier9adebed2017-04-19 01:02:49 +000052#endif // TEST_STD_VER >= 11
Howard Hinnant3e519522010-05-11 19:42:16 +000053
Howard Hinnant8f2f7e72010-08-22 00:15:28 +000054#endif // MOVEONLY_H