c++ - Wrap getter and setter with "operator[]" -


many libraries provide getter , setters access , modify there processed variables. 1 of libraries boost propertytree. want wrap getter , setter in boost::property_tree::ptree operator[].

source:

class xmldocument {     boost::property_tree::ptree ptree_;  public:     xmldocument(const std::string &content) {         std::stringstream ss;         boost::property_tree::read_xml(ss << content, ptree_);     }     template <typename t> t &operator[](const std::string &path) { /* todo */ } }  int main() {     xmldocument xml("<foo>bar</foo><baz>qux</baz>");     std::cout << xml["foo"] << std::endl; // access element.     xml["baz"] = "quux"; // modify element.     std::cout << xml["baz"] << std::endl; } 

output:

bar quux 

how can do?


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -