fork download
  1. #include <iostream> /* C++ iostream C++98/11 */
  2. #include <string> /* C++ strings C++98/11 */
  3. #include <boost/regex.hpp> /* RegEx Boost */
  4. #include <boost/optional.hpp>
  5. #include <boost/optional/optional_io.hpp>
  6.  
  7. int main() {
  8.  
  9. boost::optional<size_t> segment_idx_1 = boost::none;
  10. boost::optional<size_t> segment_idx_2 = 1;
  11.  
  12. if(segment_idx_1){
  13. std::cout << "1 -- segment_idx_1 = " << segment_idx_1.value() << std::endl;
  14.  
  15. }
  16. else{
  17. std::cout << "2 -- segment_idx_1 is none" << std::endl;
  18.  
  19. }
  20.  
  21. if(segment_idx_2){
  22. size_t res = segment_idx_2.value();
  23. std::cout << "3 -- segment_idx_2 = " << res << std::endl;
  24.  
  25. }
  26. else{
  27. std::cout << "4 -- segment_idx_2 is none "<< std::endl;
  28.  
  29. }
  30. }
Success #stdin #stdout 0.01s 5496KB
stdin
Standard input is empty
stdout
2 -- segment_idx_1 is none
3 -- segment_idx_2 = 1