AWS SDK for C++  0.12.9
AWS SDK for C++
Outcome.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <aws/core/Core_EXPORTS.h>
19 
20 #include <utility>
21 
22 namespace Aws
23 {
24  namespace Utils
25  {
26 
33  template<typename R, typename E> // Result, Error
34  class Outcome
35  {
36  public:
37 
38  Outcome() : success(false)
39  {
40  } // Default constructor
41  Outcome(const R& r) : result(r), success(true)
42  {
43  } // Result copy constructor
44  Outcome(const E& e) : error(e), success(false)
45  {
46  } // Error copy constructor
47  Outcome(R&& r) : result(std::forward<R>(r)), success(true)
48  {
49  } // Result move constructor
50  Outcome(E&& e) : error(std::forward<E>(e)), success(false)
51  {
52  } // Error move constructor
53  Outcome(const Outcome& o) :
54  result(o.result),
55  error(o.error),
56  success(o.success)
57  {
58  }
59 
61  {
62  if (this != &o)
63  {
64  result = o.result;
65  error = o.error;
66  success = o.success;
67  }
68 
69  return *this;
70  }
71 
72  Outcome(Outcome&& o) : // Required to force Move Constructor
73  result(std::move(o.result)),
74  error(std::move(o.error)),
75  success(o.success)
76  {
77  }
78 
80  {
81  if (this != &o)
82  {
83  result = std::move(o.result);
84  error = std::move(o.error);
85  success = o.success;
86  }
87 
88  return *this;
89  }
90 
91  inline const R& GetResult() const
92  {
93  return result;
94  }
95 
96  inline R& GetResult()
97  {
98  return result;
99  }
100 
106  {
107  return std::move(result);
108  }
109 
110  inline const E& GetError() const
111  {
112  return error;
113  }
114 
115  inline bool IsSuccess() const
116  {
117  return this->success;
118  }
119 
120  private:
121  R result;
122  E error;
123  bool success;
124  };
125 
126  } // namespace Utils
127 } // namespace Aws
R && GetResultWithOwnership()
Definition: Outcome.h:105
Outcome(Outcome &&o)
Definition: Outcome.h:72
Definition: json.h:1499
Outcome & operator=(Outcome &&o)
Definition: Outcome.h:79
Outcome & operator=(const Outcome &o)
Definition: Outcome.h:60
const E & GetError() const
Definition: Outcome.h:110
const R & GetResult() const
Definition: Outcome.h:91
bool IsSuccess() const
Definition: Outcome.h:115
Outcome(const E &e)
Definition: Outcome.h:44
Outcome(const Outcome &o)
Definition: Outcome.h:53
Outcome(const R &r)
Definition: Outcome.h:41
JSON (JavaScript Object Notation).