Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
invalid.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_INVALID_H_
19 #define ION_BASE_INVALID_H_
20 
21 #include <cstring> // For size_t.
22 
23 namespace ion {
24 namespace base {
25 
29 extern ION_API const size_t kInvalidIndex;
30 
34 template <typename T> static const T& InvalidReference() {
35  return *reinterpret_cast<const T*>(&kInvalidIndex);
36 }
37 
41 template <typename T> bool IsInvalidReference(const T& value) {
42  return &value == &InvalidReference<T>();
43 }
44 
47 template <typename EnumType> EnumType InvalidEnumValue() {
49  int bad_value = -1;
50  return static_cast<EnumType>(bad_value);
51 }
52 
53 } // namespace base
54 } // namespace ion
55 
56 #endif // ION_BASE_INVALID_H_
bool IsInvalidReference(const T &value)
IsInvalidReference() returns true if a passed const reference of type T has an address of InvalidRefe...
Definition: invalid.h:41
const size_t kInvalidIndex
kInvalidIndex is a size_t value that is very unlikely to be a valid index.
Definition: invalid.cc:23
double value
EnumType InvalidEnumValue()
InvalidEnumValue() returns an invalid enum value, assuming that -1 is not a valid value...
Definition: invalid.h:47