IMP  2.4.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-2015 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 #include <boost/config.hpp>
13 
14 namespace IMP {
15 #ifdef IMP_DOXYGEN
16 /** The C++0x standard adds the nullptr keyword to get around a variety of
17  problems with NULL. We provide an emulation within the IMP namespace when
18  it is not available.
19 
20  Use "nullptr" in code; the compiler will use our IMP::nullptr emulation
21  automatically on systems that don't provide a native nullptr implementation.
22 
23  If you are not in the IMP namespace, use the IMP_NULLPTR macro rather
24  than asking for "IMP::nullptr". The latter does not work with some compilers
25  (e.g. MSVC, which gets confused because nullptr is a keyword).
26 */
27 const std::nullptr_t nullptr;
28 
29 // depending on boost version
30 #elif(defined(BOOST_NO_CXX11_NULLPTR) || defined(BOOST_NO_NULLPTR)) && \
31  !defined(nullptr)
32 
33 #if !defined(SWIG)
34 
35 #if __GNUC__ &&__GNUC__ == 4 && __GNUC_MINOR__ >= 6
36 IMP_GCC_PRAGMA(diagnostic push)
37 IMP_GCC_PRAGMA(diagnostic ignored "-Wc++0x-compat")
38 #endif
39 
40 struct nullptr_t {
41  template <class O>
42  operator O *() const {
43  return static_cast<O *>(NULL);
44  }
45  /*template <class O, class C>
46  operator O C::*() const {
47  return static_cast<const O*>(NULL);
48  }*/
49 };
50 template <class O>
51 inline bool operator==(O *a, nullptr_t o) {
52  return a == static_cast<O *>(o);
53 }
54 template <class O>
55 inline bool operator!=(O *a, nullptr_t o) {
56  return a != static_cast<O *>(o);
57 }
58 extern IMPBASEEXPORT const nullptr_t nullptr;
59 
60 #if __GNUC__ &&__GNUC__ == 4 && __GNUC_MINOR__ >= 6
61 IMP_GCC_PRAGMA(diagnostic pop)
62 #endif
63 
64 #else // SWIG
65 extern const void *const nullptr;
66 #endif // SWIG
67 #endif // IMP_DOXYGEN
68 }
69 
70 #endif /* IMPBASE_NULLPTR_H */