c++ - How can I determine the actual type of an 'auto' variable -


in response:

https://stackoverflow.com/a/14382318/1676605

this program given:

std::vector<int> vi{ 0, 2, 4 }; std::vector<std::string> vs{ "1", "3", "5", "7" }; (auto : redi::zip(vi, vs))     std::cout << i.get<0>() << ' ' << i.get<1>() << ' '; 

i have no idea type of auto i is, making harder reuse expertise , learn examples. here changing auto i char i returns

in function ‘int main()’:| /data/cbworkspace/testzip/testzip.cpp|14|error: cannot convert ‘boost::iterator_facade<boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int> > > >, boost::tuples::cons<int&, boost::tuples::cons<int&, boost::tuples::null_type> >, boost::random_access_traversal_tag, boost::tuples::cons<int&, boost::tuples::cons<int&, boost::tuples::null_type> >, long int>::reference {aka boost::tuples::cons<int&, boost::tuples::cons<int&, boost::tuples::null_type> >}’ ‘char’ in initialization| /data/cbworkspace/testzip/testzip.cpp|14|warning: unused variable ‘i’ [-wunused-variable]| ||=== build finished: 1 errors, 1 warnings (0 minutes, 0 seconds) ===| 

try figure out type that.

is there way figure out type variable of auto in c++11? more clear, have struct this:

struct eventdata {     // return value redi::zip<std::vector<pricequote>, std::vector<pricequote>> goes here????? redi::zip zipping pricequote, pricequote of bids , asks. };  struct pricequote {    double price;    double size; }; 

why want put type in struct? it's not designed used (i should know, wrote it!) if necessary can use decltype , std::declvalto determine type (which still give right answer if change implementation of redi::zip)

struct eventdata {   // type returned redi::zip   typedef decltype(redi::zip(std::declval<v1>(), std::declval<v2>())) zipper_type;    // type referred zipper_type::iterator   typedef std::iterator_traits<zipper_type::iterator>::value_type zipped_type;    zipper_type m_zipper; }; 

n.b. why creating typedef struct? c++ not c, stop it.

i have no idea type of auto is, making harder reuse expertise , learn examples.

get used it. know type std::bind returns? know type std::mem_fn returns? know type lambda expression creates? no, don't need know, need know properties has , what can it, not it's called or types contains.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -