Advertisement
Vultraz

Untitled

Mar 30th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. template<typename T>
  2. std::string variant_container<T>::to_string_impl(bool annotate, bool annotate_empty, std::function<std::string(variant&)> mod_func) const;
  3. {
  4.     std::ostringstream ss;
  5.  
  6.     if(annotate) {
  7.         ss << "[";
  8.     }
  9.  
  10.     bool first_time = true;
  11.  
  12.     for(const auto& member : container_) {
  13.         if(!first_time) {
  14.             ss << ",";
  15.         }
  16.  
  17.         first_time = false;
  18.  
  19.         if(type_ == TYPE_LIST) {
  20.             ss << mod_func(member);
  21.         } else if(type_ == TYPE_MAP) {
  22.             ss << mod_func(member.first);
  23.             ss << "->";
  24.             ss << mod_func(member.second);
  25.         }
  26.     }
  27.  
  28.     // TODO: evaluate if this really needs to be separately conditional.
  29.     if(annotate_empty && container_->empty()) {
  30.         ss << "->";
  31.     }
  32.  
  33.     if(annotate) {
  34.         ss << "]";
  35.     }
  36.  
  37.     return ss.str();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement