3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2015 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Template for values that may not exist.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
31 // \note Type T is always aligned to same alignment as deUint64.
32 // \note This type always uses at least sizeof(T*) + sizeof(deUint64) of memory.
41 Maybe<T>& operator= (const T& val);
43 Maybe (const Maybe<T>& other);
44 Maybe<T>& operator= (const Maybe<T>& other);
46 const T& get (void) const;
47 const T& operator* (void) const { return get(); }
49 const T* operator-> (void) const;
50 operator bool (void) const { return m_ptr; }
57 deUint8 m_data[sizeof(T)];
60 } DE_WARN_UNUSED_TYPE;
63 Maybe<T> nothing (void)
69 Maybe<T> just (const T& value)
71 return Maybe<T>(value);
75 Maybe<T>::Maybe (void)
81 Maybe<T>::~Maybe (void)
88 Maybe<T>::Maybe (const T& val)
91 m_ptr = new(m_data)T(val);
95 Maybe<T>& Maybe<T>::operator= (const T& val)
100 m_ptr = new(m_data)T(val);
106 Maybe<T>::Maybe (const Maybe<T>& other)
110 m_ptr = new(m_data)T(*other.m_ptr);
114 Maybe<T>& Maybe<T>::operator= (const Maybe<T>& other)
123 m_ptr = new(m_data)T(*other.m_ptr);
131 const T* Maybe<T>::operator-> (void) const
138 const T& Maybe<T>::get (void) const
146 #endif // _TCUMAYBE_HPP