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
ordecltype
, 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
Post a Comment