blob: 24bf9d75452edee2adf2013825ce6bc860938d12 [file] [log] [blame]
Vitaly Bukacbed2062015-08-17 12:54:05 -07001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_MOVE_H_
6#define BASE_MOVE_H_
7
Alex Vakulenko674f0eb2016-01-20 08:10:48 -08008#include <utility>
Vitaly Bukacbed2062015-08-17 12:54:05 -07009
Alex Vakulenko674f0eb2016-01-20 08:10:48 -080010#include "base/compiler_specific.h"
11#include "base/macros.h"
12#include "build/build_config.h"
13
14// TODO(crbug.com/566182): DEPRECATED!
15// Use DISALLOW_COPY_AND_ASSIGN instead, or if your type will be used in
16// Callbacks, use DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND instead.
17#define MOVE_ONLY_TYPE_FOR_CPP_03(type) \
18 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(type)
19
20// A macro to disallow the copy constructor and copy assignment functions.
21// This should be used in the private: declarations for a class.
Vitaly Bukacbed2062015-08-17 12:54:05 -070022//
Alex Vakulenko674f0eb2016-01-20 08:10:48 -080023// Use this macro instead of DISALLOW_COPY_AND_ASSIGN if you want to pass
24// ownership of the type through a base::Callback without heap-allocating it
25// into a scoped_ptr. The class must define a move constructor and move
26// assignment operator to make this work.
Vitaly Bukacbed2062015-08-17 12:54:05 -070027//
Alex Vakulenko674f0eb2016-01-20 08:10:48 -080028// This version of the macro adds a Pass() function and a cryptic
29// MoveOnlyTypeForCPP03 typedef for the base::Callback implementation to use.
Vitaly Bukacbed2062015-08-17 12:54:05 -070030// See IsMoveOnlyType template and its usage in base/callback_internal.h
31// for more details.
Alex Vakulenko674f0eb2016-01-20 08:10:48 -080032// TODO(crbug.com/566182): Remove this macro and use DISALLOW_COPY_AND_ASSIGN
33// everywhere instead.
34#if defined(OS_ANDROID) || defined(OS_LINUX)
35#define DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(type) \
36 private: \
37 type(const type&) = delete; \
38 void operator=(const type&) = delete; \
39 \
40 public: \
41 typedef void MoveOnlyTypeForCPP03; \
42 \
Vitaly Bukacbed2062015-08-17 12:54:05 -070043 private:
Alex Vakulenko674f0eb2016-01-20 08:10:48 -080044#else
45#define DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(type) \
46 private: \
47 type(const type&) = delete; \
48 void operator=(const type&) = delete; \
49 \
50 public: \
51 type&& Pass() WARN_UNUSED_RESULT { return std::move(*this); } \
52 typedef void MoveOnlyTypeForCPP03; \
53 \
Vitaly Bukacbed2062015-08-17 12:54:05 -070054 private:
Alex Vakulenko674f0eb2016-01-20 08:10:48 -080055#endif
Vitaly Bukacbed2062015-08-17 12:54:05 -070056
57#endif // BASE_MOVE_H_