IMP  2.1.0
The Integrative Modeling Platform
base/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 #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 
32 #if !defined(SWIG)
33 
34 #if __GNUC__ &&__GNUC__ == 4 && __GNUC_MINOR__ >= 6
35 IMP_GCC_PRAGMA(diagnostic push)
36 IMP_GCC_PRAGMA(diagnostic ignored "-Wc++0x-compat")
37 #endif
38 
39 struct nullptr_t {
40  template <class O>
41  operator O *() const {
42  return static_cast<O *>(NULL);
43  }
44  /*template <class O, class C>
45  operator O C::*() const {
46  return static_cast<const O*>(NULL);
47  }*/
48 };
49 template <class O>
50 inline bool operator==(O *a, nullptr_t o) {
51  return a == static_cast<O *>(o);
52 }
53 template <class O>
54 inline bool operator!=(O *a, nullptr_t o) {
55  return a != static_cast<O *>(o);
56 }
57 extern IMPBASEEXPORT const nullptr_t nullptr;
58 
59 #if __GNUC__ &&__GNUC__ == 4 && __GNUC_MINOR__ >= 6
60 IMP_GCC_PRAGMA(diagnostic pop)
61 #endif
62 
63 #else // SWIG
64 extern const void *const nullptr;
65 #endif // SWIG
66 #endif // IMP_DOXYGEN
67 }
68 
69 #endif /* IMPBASE_NULLPTR_H */