fork download
  1. struct P{};
  2.  
  3. struct Q{bool operator()(int);};
  4.  
  5. struct R{int operator()();};
  6.  
  7. struct S{bool operator()();};
  8.  
  9. struct T{bool operator()() const;};
  10.  
  11. struct U{bool operator()() volatile;};
  12.  
  13. struct V{bool operator()() const volatile;};
  14.  
  15. template <unsigned N>
  16. class TIntToType
  17. {
  18. TIntToType();
  19. };
  20.  
  21. template <class>
  22. struct TIsNullaryFunction
  23. {
  24. static const bool Value_ = false;
  25. };
  26.  
  27. template <class TResult>
  28. struct TIsNullaryFunction<TResult (*)()>
  29. {
  30. static const bool Value_ = true;
  31. };
  32.  
  33. template <class TFunctor>
  34. class TIsNullaryFunctor
  35. {
  36. template <class T, T>
  37. class TTester;
  38.  
  39. template <class T>
  40. static char Test(TTester<bool (T::*)(), &T::operator()>*);
  41.  
  42. template <class T>
  43. static char Test(TTester<bool (T::*)() const, &T::operator()>*);
  44.  
  45. template <class T>
  46. static char Test(TTester<bool (T::*)() volatile, &T::operator()>*);
  47.  
  48. template <class T>
  49. static char Test(TTester<bool (T::*)() const volatile, &T::operator()>*);
  50.  
  51. typedef char TTwoChars[2];
  52. template <class>
  53. static TTwoChars& Test(...);
  54.  
  55. public:
  56. static const bool Value_ = sizeof(Test<TFunctor>(0)) == 1;
  57. };
  58.  
  59. template <class TFunctor>
  60. struct TIsNullaryCallable
  61. {
  62. static const bool Value_ = TIsNullaryFunction<TFunctor>::Value_
  63. || TIsNullaryFunctor<TFunctor>::Value_;
  64. };
  65.  
  66. #include <iostream>
  67.  
  68. int main()
  69. {
  70. std::cout <<
  71. TIsNullaryCallable<int>::Value_ <<
  72. TIsNullaryCallable<P>::Value_ <<
  73. TIsNullaryCallable<Q>::Value_ <<
  74. TIsNullaryCallable<R>::Value_ <<
  75. TIsNullaryCallable<int (*)()>::Value_ <<
  76. TIsNullaryCallable<S>::Value_ <<
  77. TIsNullaryCallable<T>::Value_ <<
  78. TIsNullaryCallable<U>::Value_ <<
  79. TIsNullaryCallable<V>::Value_ << std::endl;
  80. }
  81.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
000011111