IMP  2.0.0
The Integrative Modeling Platform
nullptr.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/nullptr.h
3  * \brief Provide a nullptr keyword analog.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPBASE_NULLPTR_H
9 #define IMPBASE_NULLPTR_H
10 
11 #include <IMP/base/base_config.h>
12 
13 namespace IMP {
14 #ifdef IMP_DOXYGEN
15 /** The C++0x standard adds the nullptr keyword to get around a variety of
16  problems with NULL. We provide an emulation within the IMP namespace when
17  it is not available.
18 
19  Use "nullptr" in code; the compiler will use our IMP::nullptr emulation
20  automatically on systems that don't provide a native nullptr implementation.
21 
22  If you are not in the IMP namespace, use the IMP_NULLPTR macro rather
23  than asking for "IMP::nullptr". The latter does not work with some compilers
24  (e.g. MSVC, which gets confused because nullptr is a keyword).
25 */
26 const std::nullptr_t nullptr;
27 
28 #elif !IMP_COMPILER_HAS_NULLPTR
29 
30 #if !defined(SWIG)
31 
32 #if __GNUC__ && __GNUC__==4 && __GNUC_MINOR__>=6
33 IMP_GCC_PRAGMA(diagnostic push)
34 IMP_GCC_PRAGMA(diagnostic ignored "-Wc++0x-compat")
35 #endif
36 
37 
38 struct nullptr_t {
39  template <class O>
40  operator O*() const {
41  return static_cast<O*>(NULL);
42  }
43  /*template <class O, class C>
44  operator O C::*() const {
45  return static_cast<const O*>(NULL);
46  }*/
47 };
48 template <class O>
49 inline bool operator==(O *a, nullptr_t o) {
50  return a == static_cast<O*>(o);
51 }
52 template <class O>
53 inline bool operator!=(O *a, nullptr_t o) {
54  return a != static_cast<O*>(o);
55 }
56 extern IMPBASEEXPORT const nullptr_t nullptr;
57 
58 #if __GNUC__ && __GNUC__==4 && __GNUC_MINOR__>=6
59 IMP_GCC_PRAGMA(diagnostic pop)
60 #endif
61 
62 #else // SWIG
63 extern const void * const nullptr;
64 #endif //SWIG
65 #endif // IMP_DOXYGEN
66 
67 }
68 
69 #endif /* IMPBASE_NULLPTR_H */