fork(1) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. using namespace std;
  5.  
  6. class Incomplete;
  7. class Complete {};
  8.  
  9. template <typename IncompleteType>
  10. struct DetermineCompleteHelper : public IncompleteType {};
  11.  
  12. template <typename IncompleteType, typename = std::enable_if_t<true>>
  13. struct DetermineComplete {
  14. static constexpr const bool value = false;
  15. };
  16.  
  17. template <typename IncompleteType>
  18. struct DetermineComplete<IncompleteType, std::enable_if_t<std::is_same<
  19. decltype(DetermineCompleteHelper<IncompleteType>{}),
  20. decltype(DetermineCompleteHelper<IncompleteType>{})>::value>> {
  21. static constexpr const bool value = true;
  22. };
  23.  
  24. int main() {
  25. cout << DetermineComplete<Complete>::value << endl;
  26. cout << DetermineComplete<Incomplete>::value << endl;
  27. return 0;
  28. }
  29.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘struct DetermineCompleteHelper<Incomplete>’:
prog.cpp:26:42:   required from here
prog.cpp:10:8: error: invalid use of incomplete type ‘class Incomplete’
 struct DetermineCompleteHelper : public IncompleteType {};
        ^~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:6:7: note: forward declaration of ‘class Incomplete’
 class Incomplete;
       ^~~~~~~~~~
stdout
Standard output is empty