fork(2) download
  1. #include <iostream>
  2. #include <cassert>
  3.  
  4. // The Official proposal
  5. // http://w...content-available-to-author-only...d.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf
  6. const // this is a const object...
  7. class {
  8. public:
  9. template<class T> // convertible to any type
  10. operator T*() const // of null non-member
  11. {
  12. return 0;
  13. } // pointer...
  14.  
  15. template<class C, class T> // or any type of null
  16. operator T C::*() const // member pointer...
  17. {
  18. return 0;
  19. }
  20.  
  21. private:
  22. void operator&() const; // whose address can't be taken
  23. } my_nullptr = {}; // and whose name is nullptr
  24.  
  25.  
  26. struct Test123 {
  27. int ABCD, ABC, AB;
  28. int A;
  29. int BA, CBA, DCBA;
  30. struct XYZ {
  31. char X, Y, Z, W;
  32. };
  33. struct {
  34. int B, C, D;
  35. };
  36. } test123;
  37.  
  38.  
  39. class Test {
  40. int ABCD;
  41. public:
  42. void method(void){}
  43.  
  44. Test(int val) :ABCD(val){}
  45. int getABCD(void) const { return ABCD; }
  46. int get2ABCD(void) const { return ABCD * 2; }
  47. int get3ABCD(void) const { return ABCD * 3; }
  48. } test(0123);
  49.  
  50.  
  51. int main(int argc, char* argv[])
  52. {
  53.  
  54. // TEST_my_nullptr
  55. {
  56. int a = 321, *p = my_nullptr;
  57. assert(p == my_nullptr);
  58. assert(my_nullptr == p);
  59.  
  60. p = &a; *p = 0123;
  61. assert(p != my_nullptr);
  62. assert(my_nullptr != p);
  63.  
  64. p = my_nullptr;
  65.  
  66. int(*mainptr)(int argc, char** argv) = my_nullptr;
  67. assert(mainptr == my_nullptr);
  68. assert(my_nullptr == mainptr);
  69. }
  70.  
  71.  
  72. // TEST_my_nullptr_const
  73. {
  74. const int a = 321, *p = my_nullptr;
  75. assert(p == my_nullptr);
  76. assert(my_nullptr == p);
  77.  
  78. p = &a;
  79. assert(p != my_nullptr);
  80. assert(my_nullptr != p);
  81.  
  82. const int** ptr = my_nullptr;
  83.  
  84. assert(ptr == my_nullptr);
  85. assert(my_nullptr == ptr);
  86.  
  87. ptr = &p;
  88. assert(ptr != my_nullptr);
  89. assert(my_nullptr != ptr);
  90. assert(*ptr != my_nullptr);
  91. assert(my_nullptr != *ptr);
  92.  
  93. }
  94.  
  95.  
  96. // TEST_my_nullptr_member
  97. {
  98. int Test123::*pINT = my_nullptr;
  99. assert(pINT == my_nullptr);
  100. assert(my_nullptr == pINT);
  101.  
  102. pINT = &Test123::ABCD;
  103. assert(pINT != my_nullptr);
  104. assert(my_nullptr != pINT);
  105.  
  106. test123.*pINT = 0123;
  107.  
  108. const int Test123::*pCINT = my_nullptr;
  109. assert(pCINT == my_nullptr);
  110. assert(my_nullptr == pCINT);
  111.  
  112. pCINT = &Test123::ABCD;
  113. assert(pCINT != my_nullptr);
  114. assert(my_nullptr != pCINT);
  115.  
  116. assert(test123.*pCINT == test123.*pINT);
  117. }
  118.  
  119. // TEST_my_nullptr_Function
  120. {
  121. void (Test::*pm)(void) = my_nullptr;
  122.  
  123. pm = &Test::method;
  124.  
  125. int (Test::*pABCD)(void) const = my_nullptr; // This F**k Line In VS2013
  126.  
  127. pABCD = &Test::getABCD;
  128.  
  129. int a1 = (test.*pABCD)();
  130.  
  131. pABCD = &Test::get2ABCD;
  132. int a2 = (test.*pABCD)();
  133.  
  134. pABCD = &Test::get3ABCD;
  135. int a3 = (test.*pABCD)();
  136.  
  137. assert(a1 + a2 == a3);
  138. }
  139.  
  140. std::cout << "All Tests for my_nullptr Passed!" << std::endl;
  141. return 0;
  142. }
  143.  
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
All Tests for my_nullptr Passed!