c++11 - c++ decltype how to use to simplify variable definition -


say, have piece of code, in 1 of classes, defines

  • a map of key , map
  • the second map key , function handler
  • the function hander signature takes 2 params

right now, signature define variable looks incredible.

std::map<std::string, std::map<std::string,     std::function<void(std::shared_ptr<httprequest>,         std::shared_ptr<httpresponse>)>>> routefunctions_; 

i came know decltype, unable use correctly.

decltype(x) routefunctions_;  // should there in place of x ? 

  • use typedef type, if declare variables of it.
  • use auto or decltype, if want return value of type function.
  • use decltype, if want type of structure/class member.

look @ articles:

http://en.cppreference.com/w/cpp/language/auto http://en.cppreference.com/w/cpp/language/decltype

http://www.cprogramming.com/c++11/c++11-auto-decltype-return-value-after-function.html

your choice in case typedef:

typedef std::map<std::string, std::map<std::string, std::function<void(std::shared_ptr<httprequest>, std::shared_ptr<httpresponse>)>>> routefunctionscontainer;  routefunctionscontainer routefunctions_; 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -