fork download
  1. #include <iostream>
  2. #include "boost/optional.hpp"
  3. using namespace std;
  4.  
  5. struct No_data{
  6. operator bool() const{
  7. return false;
  8. }
  9. };
  10.  
  11. template<typename T>
  12. struct Data {
  13. T t;
  14. operator bool() const {
  15. return true;
  16. }
  17. };
  18.  
  19.  
  20. template<typename T>
  21. struct myOptional {
  22. union {
  23. Data<T> t;
  24. No_data nd;
  25. } data;
  26. };
  27. int main(){
  28. myOptional<bool> ob;
  29. cout << sizeof(myOptional<bool>) << endl;
  30. return 0;
  31. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
1